英文:
Can we keep first element as a blank while declaring constant using useState?
问题
可以我们写
const [, setOpenCollapse] = React.useState(false);
吗?如果我在使用React中的useState声明常量时将第一个元素保留为空白,这是否是有效的语法?
英文:
Can we write
const [, setOpenCollapse] = React.useState(false);
? Is this a valid syntax if I kept first element as a blank while declaring constant using useState in React?
答案1
得分: 1
这段代码在语法上是有效的,可以编译。然而,以这种方式编写代码时,您将没有对状态的引用,因此将无法使用它。
如果不使用状态,那么拥有状态就没有意义。
英文:
Syntactically this code is valid, it will compile. However, when writing like this you will have no reference to the state and therefore won't be able to use it.
There is no point in having a state if you are not using it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论