React Hooks 使用指南
React Hooks 是 React 16.8 引入的新特性,它让你在不编写 class 的情况下使用 state 以及其他的 React 特性...
import React, { useState } from 'react';
function Example() {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
上面的代码展示了如何使用 useState Hook 来管理组件的状态...
阅读更多