React 文档声明: 不要在循环、条件或嵌套函数内调用 Hook。
调用钩子是否意味着只是调用useState
eg const [state, useState] = useState(0)
?
在条件中调用 setter 怎么样?
这段代码是否违反了钩子规则?
const [oneHook, setOneHook] = useState(0)
const [anotherHook, setAnotherHook] = useState(false)
if (something) {
setOneHook(1)
setAnotherHook(true)
} else {
setOneHook(0);
setAnotherHook(false)
}
谢谢 !