gpt4 book ai didi

Redux - 有什么方法可以访问 reducer 中的存储树?

转载 作者:行者123 更新时间:2023-12-03 15:05:16 27 4
gpt4 key购买 nike

就我而言,我有一家像这样的商店:

{
aa: {...},
bb: cc // the result of computing with aa
}

我需要更新 aabb同时,但 bb需要获取 aa 的最新计算.

这是一些代码(React.js):
onClick(e) {
const { dispatch, aa, bb } = this.props;

dispatch(updateAa());
dispatch(updateBb(aa)); // can not get the latest computation of aa, it is the last computation..
}

那么,这是否意味着我需要获得 aabb reducer ?

我该怎么做?

希望有帮助!,谢谢!

最佳答案

不要使用 combineReducers.
示例

替换此代码

export const a = combineReducers({
app,
posts,
intl,
products,
pos,
cats,
});


export default (state = {}, action) => {
return {
app: app(state.app, action, state),
posts: posts(state.posts, action, state),
intl: intl(state.intl, action, state),
products: products(state.products, action, state),
pos: pos(state.pos, action, state),
cats: cats(state.cats, action, state),
};
};

reducer 就像
const reducer = (state = initialState, action, root) => {....}

关于Redux - 有什么方法可以访问 reducer 中的存储树?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34419809/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com