gpt4 book ai didi

reactjs - react native : Assigning value with setState()

转载 作者:行者123 更新时间:2023-12-04 10:01:12 24 4
gpt4 key购买 nike

这里,处理函数中的 props 名称与 state 中的名称相同,都是 `phone'

state = {
phone: '',
}

.
<TextInput
onChangeText={this.handlePhoneChange}
/>

.
handlePhoneChange = phone => {
this.setState({phone})
}

不应该是 this.setState({phone:phone}) ?这两个陈述是同义词还是我遗漏了什么?

最佳答案

New in JavaScript with ES6/ES2015, if you want to define an object who's keys have the same name as the variables passed-in as properties, you can use the shorthand and simply pass the key name.



这是 , 的简短语法
{phone : phone}

如果键名与变量名相同,您可以像这样使用它:
{phone}

ALSO DO READ

关于reactjs - react native : Assigning value with setState(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61812553/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com