- hook不能在calss组件中使用
- 只能在函数最外层调用hook,不要在循环,条件判断或子函数中调用
- 只能在react的函数组件中调用hook,不要在其他js函数中调用
useState
//基础类型
const [count,setCount] = useState(0);
setState(count + 1)
setState(() => {
count + 1
})
//引用类型
const [tc,setTc] = useState({name:"aa",age:18});
setTc(()=>{
return {
...tc
}
})