【发布时间】:2020-02-11 03:18:21
【问题描述】:
我正在开发 React Native 项目,我使用 React Native 组件创建了表单。 我使用 TextInput 来编辑这样的状态值:
<TextInput
shake
keyboardAppearance='light'
autoFocus={false}
autoCapitalize='none'
autoCorrect={false}
keyboardType='default'
returnKeyType='next'
value={this.state.sector}
onChangeText={sector => this.setState({ sector })}
/>
使用 console.log 扇区值,我在输入更改后正确地获得了当前值,但我已经看到了一些这样的 ref 示例:
<TextInput
shake
keyboardAppearance='light'
autoFocus={false}
autoCapitalize='none'
autoCorrect={false}
keyboardType='default'
returnKeyType='next'
value={this.state.sector}
ref={input => (this.sectorInput = input)}
onChangeText={sector => this.setState({ sector })}
/>
我不明白这个操作:
ref={input => (this.sectorInput = input)}
有人可以解释什么是 ref 以及我们为什么使用 input 以及何时应该使用 ref ?
【问题讨论】:
标签: forms react-native ref