In my case, I have a store like:
{
aa: {...},
bb: cc // the result of computing with aa
}
I need to update aa
and bb
at the same time, but bb
need to get the latest computation of aa
.
Here is some code(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..
}
So, is this mean that I need to get aa
in bb
's reducer?
And How can I do it?
Hope for helps!, Thanks!
There are several possibilities, but it's tough to say which is best, given the vagueness of the code.
props
. In this workflow, aa
and bb
would each be produced by selector functions, rather than stored in that store itself.aa
and bb
outside of combineReducers
, so that it sees the whole state, rather than the state scoped down to aa
and bb
.updateAa
and updateBb
, and pass enough info in each action to make the calculation.