[英]Can't set default value to useState
I am new in React and do not understand why this lines doesn't work:我是 React 新手,不明白为什么这条线不起作用:
const { showProjects, setShowProjects } = useState(true);
console.log(showProjects);
Currently it returns undefined
when I am trying to make it return true
for example.目前,当我试图让它返回
true
时,它返回undefined
。
const [showProjects, setShowProjects] = useState(true);
console.log(showProjects);
You have to define hooks const this way:您必须以这种方式定义钩子 const:
const [ showProjects, setShowProjects ] = useState(true); const [ showProjects, setShowProjects ] = useState(true);
See useState docs查看useState 文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.