reactjs - 从 mapStateToProps 传递 Prop 到 Dispatch Action 是未定义的
问题描述
我正在尝试使用 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 和 lobby 似乎被定义为文档引用正在工作,但 xp 未定义?
解决方案
推荐阅读
- mapster - Mapster - 如何访问父对象
- amazon-web-services - AWS VPN 到 AWS VPC
- python-3.x - 查找python数组变为正数(但不是负数)的索引
- python - 无法使用 Python 的 BeasutifulSoup4 / 提取从某些 url 中刮取标题
- python - Discord.py 重写和发送图像 - AttributeError: 'list' object has no attribute 'send'
- java - 是否可以为 Java 11 和 java 模块生成休眠元模型?
- c++ - C 样式字符串数组首先有效,然后不可读
- list - 如何在修改列表时迭代 Xamarin.Forms.Maps Map.Pins 列表?
- php - PHP 7.3 遇到非数字值
- python - 在 tensorflow.keras 中使用 BinaryCrossentropy(from_logits=True) 时应该使用什么作为目标向量