Answer the question
In order to leave comments, you need to log in
How to access store from reducer?
Let's say the store is composite:
rootReducer = combineReducers({
reducer1: reducer1,
reducer2: reducer2
})
function reducer1(state ={data: []}, action) {
switch (action.type) {
case SOME_ACTION:
return {...state, data[store.reducer2.id]: action.payload}
default:
return state
}
}
Answer the question
In order to leave comments, you need to log in
You need to use middleware. For example redux-thunk
const action = value => (dispatch, getState) => {
const otherValue = otherValueSelector(getState());
const payload = calculate(value, otherValue);
dispatch(otherAction(payload));
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question