Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TextInput return type in React Native

I was trying to update firebase database with useState that got its value from TextInput. But apparently the useState datatype changed to object instead of string. How do I go about this since firebase only takes string to update the database.

 const UpdateUser = async () => {
try {
  db.ref("users/" + auth.currentUser.uid).update({
    name: newuser,
  });
} catch (error) {
  alert(error);
}
setNewuser("");};

TextInput Code:

 <View>
    <Text style={styles.ProfileName}>Display Username:</Text>
    <TextInput
      placeholder={user}
      value={newuser}
      onChange={(text) => {
        setNewuser(text);
      }}
    />
    <Button onPress={UpdateUser} title="Change" />
  </View>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

onChangeText is a simple prop, that gives whatever is the value of the input field on every change.//string

onChange passes an event with { nativeEvent: { eventCount, target, text} }. //object

You can find more about the difference here.
Simply change it to onChangeText will work.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading