gpt4 book ai didi

javascript - 未捕获的 TypeError : Object (. ..) 不是一个函数

转载 作者:行者123 更新时间:2023-12-01 00:24:07 25 4
gpt4 key购买 nike

我对 Preact 很陌生,当我想在 Preact 中使用钩子(Hook)时,出现错误:

Uncaught TypeError: Object(...) is not a function

我不知道该怎么办,网上有一些关于 Preact 的文章

这是我的代码

import './style';
import { useState } from 'preact';

function App() {
const [value, setValue] = useState(0);
const increment = useCallback(() => setValue(value + 1), [value]);

return (
<div>
Counter: {value}
<button onClick={increment}>Increment</button>
</div>
);
}

export default App

最佳答案

您导入错误。应该是:

import { useState } from 'preact/hooks';

请参阅此处的文档:https://preactjs.com/guide/v10/hooks/#usestate

关于javascript - 未捕获的 TypeError : Object (. ..) 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59156903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com