基本用法
const [age, setAge] = useState(22);
const [age, setAge] = useState(generateAge); //传入函数生成初始值,此函数只会在首次渲染执行一次
//更新状态
setAge(val)
setAge((preState)=>{ return preState +1}); //state有快照概念,一次渲染周期中只能获取到上次渲染的快照值,即使本次渲染修改了state值
//值为对象或数组,需创建新引用
setForm({
...form,
key: val
})
//值为一个函数
const [fun, setFun] = useState(()=> someFunction)
setFun(()=>{someOtherFunction})
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。