【发布时间】:2018-10-26 12:58:30
【问题描述】:
我刚刚读到了 react 的新功能钩子。Read about hooks 但我无法使用它。 它给了我错误。
我目前使用的是 16.6.0 版
我终于明白了钩子。
import React, {useState} from 'react';
const Fun = () => {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);}
export default Fun;
我作为 Fun 导入并在我的 app.js 文件中使用
我犯的错误是我没有安装 React v16.7.0-alpha 所以我使用 npm add react@next react-dom@next 安装。
谢谢
【问题讨论】:
-
据我所知,React Hooks 已移至 16.7.0-alpha.2。
标签: javascript reactjs react-hooks