这个问题在这里已经有了答案:
Accessing Redux state in an action creator?
(8 个回答)
2年前关闭。
在下面的示例中,从 firebase 获取数据后,我想添加 redux 存储中已经存在的用户对象并将其附加到所有消息对象中。请求你帮忙。
问题:
db.collection(`messages/${documentId}/chat`)
.get()
.then(snapshot => {
const messages = [];
snapshot.docs.forEach(doc => {
console.log("message", doc.id, doc.data());
messages.push({
id: doc.id,
from: doc.data().from,
to: doc.data().to,
text: doc.data().text,
timestamp: doc.data().timestamp.seconds * 1000
});
});
dispatch({ type: GET_CHAT, payload: messages });
});
最佳答案
如果您使用 Redux Thunk 中间件,您可以简单地这样做:
const myAction = () => async (dispatch, getState) => {
const { field1, field2 } = getState().myReducer;
};
关于react-native - 在 Redux 中,如何让状态生效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55194768/