react笔记
Hook 只能在组件函数的顶层调用
错误示范如下:
if (isSent) {
return <h1>Thank you!</h1>;
} else {
// eslint-disable-next-line
const [message, setMessage] = useState('');
}
正确示范:
const [isSent, setIsSent] = useState(false);
const [message, setMessage] = useState('');
if (isSent) {
return <h1>Thank you!</h1>;
} else {
}