无法读取 null 的属性(读取“__hooks”)

问题描述 投票:0回答:1

为了在 Deno Fresh 中使用 Reveal.js,我在岛上使用了以下代码:

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)       

会发生什么?

react-hooks preact freshjs
1个回答
1
投票

您正在混合构建的生产代码和源代码(

/hooks/src/...
),这是您无法做到的。

使用内置的钩子输出:

https://esm.sh/v128/[email protected]/hooks

© www.soinside.com 2019 - 2024. All rights reserved.