javascriptreact-nativetextinput

TextInput with value doesn't change value


In my react-native app i have an API that I'm retrieving data from, and I'm setting the data inside my input values, user should be able to edit those inputs and update, but when i try to type in the input it won't type anything and the value stays as it is, here is the TextInput code:

<TextInput
   placeholder= Email
   value={this.state.info.email}
   onChangeText={email => this.setState({ email })}/>

Solution

  • Since I don't think email is the only prop of your state.info I recommend you to use setState() properly, in order to modify just that field. According to immutability and ES6, something like:

    <TextInput
      placeholder="Email"
      value={this.state.info.email}
      onChangeText={text =>
        this.setState(state => ({
          info: {
            ...state.info,
            email: text
        }))
      }
    />;
    

    Read more about handling TextInput here