developer11
developer11

Reputation: 35

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:

enter image description here

Upvotes: 0

Views: 995

Answers (1)

Ankush Rishi
Ankush Rishi

Reputation: 3190

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})

Upvotes: 1

Related Questions