[英]state not updating in reducer in react native
I'm using react-redux for mantaining state of my app.我正在使用 react-redux 来维护我的应用程序的 state。 This is my action这是我的行动
case 'set_user_name':
user.updateProfile({displayName: action.payload});
database().ref(`Users/${state.user.id}/name`).set(action.payload);
return {
...state,
name: action.payload,
};
In this action I am receiving name perfectly and in my database it is also updating fine but it does not update my name in state.在此操作中,我完美地接收到名称,并且在我的数据库中它也在正常更新,但它没有更新我在 state 中的名称。 here is my state这是我的 state
if (user != null) {
Initial_state = {
defaultPic: defaultPic,
user: {
id: user ? user.uid : '',
name: user.displayName ? user.displayName : 'set name',
photoURL: user.photoURL ? user.photoURL : defaultPic,
phoneNumber: user ? user.phoneNumber : '',
fcmToken: '',
},
allUsers: '',
};
}
your Initial_state holds a user
, wich is where you place the name
attribute.您的 Initial_state 拥有一个user
,这是您放置name
属性的地方。
I am supposing that action.payload
just return the user's name我假设action.payload
只是返回用户名
update your case and check if it works.更新您的案例并检查它是否有效。
case 'set_user_name':
user.updateProfile({displayName: action.payload});
database().ref(`Users/${state.user.id}/name`).set(action.payload);
return {
...state,
user: { ...state.user, name: action.payload },
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.