代码之家  ›  专栏  ›  技术社区  ›  Ooker

无法读取null的属性(正在读取'__hook')

  •  0
  • Ooker  · 技术社区  · 7 月前

    为了 use reveal.js in Deno Fresh ,我在岛上使用此代码:

    import { useEffect } from "https://esm.sh/v128/[email protected]/hooks/src/index.js";
    import Reveal from '../reveal/js/index.js';
    
    export default function Island() {
      useEffect(()=> {
          setDeck(new Reveal());
          deck.initialize();
      }) 
      return <>Text</>
    }
    

    我认为这是使用钩子的正确方法,但我得到了以下错误:

    An error occurred during route handling or page rendering. 
    
      3 |
      4 | export default function Island() {
    > 5 |   useEffect(()=> {
        |   ^
      6 |     newFunction();
      7 |
      8 |     function newFunction() {
    
    TypeError: Cannot read properties of null (reading '__hooks')
        at s (https://esm.sh/stable/[email protected]/denonext/hooks/src.js:2:1339)
        at G (https://esm.sh/stable/[email protected]/denonext/hooks/src.js:2:2385)
        at Object.Island (file:///D:/Programming/Test/fresh-project/islands/Island.jsx:5:3)
        at m (https://esm.sh/v135/[email protected]/X-ZS8q/denonext/preact-render-to-string.mjs:2:3237)       
        at m (https://esm.sh/v135/[email protected]/X-ZS8q/denonext/preact-render-to-string.mjs:2:2543)       
        at m (https://esm.sh/v135/[email protected]/X-ZS8q/denonext/preact-render-to-string.mjs:2:3802)       
        at m (https://esm.sh/v135/[email protected]/X-ZS8q/denonext/preact-render-to-string.mjs:2:3802)       
        at m (https://esm.sh/v135/[email protected]/X-ZS8q/denonext/preact-render-to-string.mjs:2:3802)       
        at m (https://esm.sh/v135/[email protected]/X-ZS8q/denonext/preact-render-to-string.mjs:2:3802)       
        at m (https://esm.sh/v135/[email protected]/X-ZS8q/denonext/preact-render-to-string.mjs:2:3802)       
    

    会发生什么?

    1 回复  |  直到 7 月前
        1
  •  2
  •   rschristian    7 月前

    您正在混合构建代码、生产代码和源代码( /hooks/src/... ),这是你不能做的。

    使用构建的挂钩输出: https://esm.sh/v128/ [email protected] /hooks