Appearance
useState:
用于在函数组件中添加 state,可以在函数组件中保存和更新状态
基本使用
jsx
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>
);
}