简体   繁体   中英

Unable to Update in Firebase using react native

I am trying to update the firebase table using the react native and instead of updating new entry is being inserted which i dont want. Code is:

firebase.database().ref('/users1').child(this.props.navigation.state.params.keyis).set({email:this.state.email,password:this.state.password})

this.props.navigation.state.params.keyis- This contains the unique id for each row present to update. and email, password are the fields. Using this I need to update it. My key is changing after i submit so insert is happening instead of update and hence not able to compare it with the existing key. This variable comes up from previous page and is stored like this:

<TextInput style={{marginTop:20, height:40, borderColor:'gray', borderWidth:1}} onChangeText={keyis=>this.setState({keyis})} value={this.state.keyis}/>

This is the structure of database:

在此处输入图像描述

Instead of using set you need to use update . something like this:

firebase.database().ref('/users1').child(this.props.navigation.state.params.keyis).update({email:this.state.email,password:this.state.password})

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