我正在运行最新版本的React,我收到了这个错误 我有一个使用React Hooks的简单组件,如下所示: import React, { useState } from "react";const AppFunction = () = { const [count, setCount] = useState(0); const increm
我有一个使用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" },UPDATE
Hook现在作为React v16.8.0的一部分发布.您可以通过升级您的反应版本来使用挂钩
有关API的更多详细信息,请参见docs
React 16.7.0不包含钩子.
按照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.
要在代码中运行挂钩,请参阅How to use new Feature Hooks in React?