切换 React Native Firestore
Toggle Switch React Native Firestore
我正在使用 firestore 构建 React 本机应用程序,所以我切换用户位置开关,但它似乎对 post 和 firebase
不起作用
constructor(props) {
super(props);
this.state ={
toggled: this.props.currentUser.locationOn,
}
}
toggleSwitch (value){
this.setState({toggled: value})
firebase.firestore().collection("users")
.doc(firebase.auth().currentUser.uid).update({
geo_point: new firestore.GeoPoint(-6.6004, 106.8092),
locationOn: value
})
console.log('tes switch', value)
}
render(){
return(
<View style={styles.container}>
<Switch onValueChange={this.toggleSwitch}
value={this.state.toggled}/>
</View>
);
}
}
用箭头函数试试这个方法,比如
toggleSwitch = (value) => {
this.setState({toggled: value})
...
}
我正在使用 firestore 构建 React 本机应用程序,所以我切换用户位置开关,但它似乎对 post 和 firebase
不起作用constructor(props) {
super(props);
this.state ={
toggled: this.props.currentUser.locationOn,
}
}
toggleSwitch (value){
this.setState({toggled: value})
firebase.firestore().collection("users")
.doc(firebase.auth().currentUser.uid).update({
geo_point: new firestore.GeoPoint(-6.6004, 106.8092),
locationOn: value
})
console.log('tes switch', value)
}
render(){
return(
<View style={styles.container}>
<Switch onValueChange={this.toggleSwitch}
value={this.state.toggled}/>
</View>
);
}
}
用箭头函数试试这个方法,比如
toggleSwitch = (value) => {
this.setState({toggled: value})
...
}