简体   繁体   中英

How to edit value in the TextInput React native?

Setting value to the textinput from state and updating the state onChangeText. Still the value in the textInput is not changing. There is no problem while running it in the simulator. It occurs only when running in the device. Same code no problem with android device and emulator.

class CompanyDetailsInput extends Component {
constructor(props) {
    super(props)

    this.state = {
        email: props.profile.Email,
    }

render() {
    return (


                    <TextInput
                        value={this.state.email}
                        editable={this.props.editable}
                        onChangeText={(email) => {
                            this.email(email)
                        }}

                        autoCorrect={false}
                        blurOnSubmit={false}
                        returnKeyType={"next"}
                        keyboardType={"default"}
                    </TextInput>
)}
}

you'll need to setState your onChangeText , so;

class CompanyDetailsInput extends Component {
constructor(props) {
    super(props)

    this.state = {
        email: props.profile.Email,
    }

render() {
    return (
        <TextInput
          value={this.state.email}
          editable={this.props.editable}
          onChangeText={(x)=> this.setState({ email: x })}
          autoCorrect={false}
          blurOnSubmit={false}
          returnKeyType="next"
          keyboardType="default"
        />
       )
      }
     }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM