react-native - React Native TextInput 不更新状态

标签 react-native

好吧,这是一个令人尴尬的问题,但我无法让这个 TextInput 接受我输入的值。

它只是在我键入它时尽可能快地删除它 - 我很确定记录 this.state.code 会显示一个空变量。

是不是我的键盘类型有问题?我需要执行 .toString() 吗?

constructor() {
    super()
    this.state = {
        code: '12'
    }
}

<TextInput
    onChangedText={(text) => this.setState({code: text})}
    value={this.state.code}
    keyboardType='numeric'
    style={styles.input}
    placeholder='Code'
    maxLength={4}
/>

最佳答案

正确的属性是onChangeText。不是 onChangedText

关于react-native - React Native TextInput 不更新状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43131236/

相关文章:

javascript - React-native pubnub WebRTC 视频聊天

android - Gradle 构建工具找不到 runtime.jar?

ios - onShouldStartLoadWithRequest 在 iOS React Native 中自动调用 WebView 中加载任何 url,如何控制它?

javascript - 创建接收包含属性 "props"的 "message"的 React 组件

react-native - 为什么不生成设备 token ?

javascript - React Native,onPress 不适用于从 fontAwesome 导入的图标

node.js - -bash : react-native: command not found

react-native - 如何修复 console.error : "This browser lacks typed array (Uint8Array) support which is required by buffer v5.x. Use buffer v4.x if ..."

android - react native 运行安卓;未找到 SDK 位置,但它存在于路径中

javascript - 我尝试将文本组件发送到屏幕末尾,但它不起作用