我正在尝试使用mapStateToProps中的值调度动作。错误信息:
FirebaseError:函数DocumentReference.update()用无效数据调用。不支持的字段值:未定义(在字段xp中找到)
主文件中的设置:
componentWillReceiveProps(){
this.props.updateInLobby({
userid: this.props.auth,
xp: this.props.user.xp,
lobby: this.props.match.params.id,
}
...
const mapStateToProps = (state, ownProps) =>{
return{
user: state.firebase.profile,
auth: state.firebase.auth.uid,
}
}
const mapDispatchToProps = (dispatch) =>{
return{
updateInLobby: (data) => {dispatch(updateInlobby(data))},
}
}
export default compose(
connect(mapStateToProps, mapDispatchToProps),
firestoreConnect((props)=>{
return[
{collection: "lobby@"+props.match.params.id}]
})
)(RootLobby);
调度操作文件:
export const updateInlobby = (data) =>{
return(dispatch, getState, {getFirestore}) =>{
const firestore = getFirestore();
firestore.collection("lobby@"+data.lobby).doc(data.userid).update({
xp: data.xp
})
}
为什么在文档引用有效的情况下似乎已定义了userid和大厅,但未定义xp?