繁体   English   中英

切换 React Native Firestore

[英]Toggle Switch React Native Firestore

我正在使用firestore构建react native应用程序,所以我用这个开关来打开和关闭用户位置,但它似乎无法发布到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> ); } }

用箭头 function 试试这种方式

toggleSwitch = (value) => {
   this.setState({toggled: value})
   ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM