gpt4 book ai didi

reactjs - React 16.7 中的 React Hooks 问题 TypeError : Object(. ..) 不是一个函数

转载 作者:行者123 更新时间:2023-12-03 13:16:28 25 4
gpt4 key购买 nike

我正在运行最新版本的 React,但收到此错误 enter image description here我有一个使用 React Hooks 的简单组件,如下所示:

import React, { useState } from "react";

const AppFunction = () => {
const [count, setCount] = useState(0);

const incrementCount = () => {
setCount(count + 1);
};
return (
<div>
<h1>Count:{count} </h1>
<button onClick={incrementCount}>Click Me</button>
</div>
);
};

export default AppFunction;

我在堆栈溢出上找到的所有内容都说要升级库,但我有最新版本(16.7.0)并且尝试了 alpha 版本,但没有成功,我做错了什么?

package.json

"dependencies": {
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-scripts": "2.1.1"
},

最佳答案

更新

Hooks 现已作为 React v16.8.0 的一部分发布。您可以通过升级react版本来使用hooks

参见docs 有关 API 的更多详细信息

<小时/>

React 16.7.0 不包含钩子(Hook)。

根据 React blog

Our latest release includes an important performance bugfix for React.lazy. Although there are no API changes, we’re releasing it as a minor instead of a patch.

为了在代码中运行 Hook ,请参阅 How to use new Feature Hooks in React?

关于reactjs - React 16.7 中的 React Hooks 问题 TypeError : Object(. ..) 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53861645/

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