Answer the question
In order to leave comments, you need to log in
How correct is it to take store.getState() in action creators?
how correct is it to take store.getState() in action creators? is it possible to do so? this will make reducers cleaner, leave more logic in actions, what else can be pluses, and what can be minuses?
example
export function changePassWithCode(body = {}) {
body.email = store.getState().authorizationReducer.emailForForgotPass;
body.validationCode = store.getState().authorizationReducer.ForgotPassValidationCode;
const
url = `${config.apiUrl}/user/myFuckingAPIOnPHP`,
isRSAA = true;
return {type: POST_AUTHORIZATION_CHANGE_FORGOT_PASSWORD, url, isRSAA, body};
}
Answer the question
In order to leave comments, you need to log in
In general, this approach is not an anti-pattern, it depends on the situation. If the project uses redux-thunk, then it is more convenient to do it directly from the function, the second parameter of thunk is the getState method
export const SOME_ACTION = 'SOME_ACTION';
export function someAction() {
return (dispatch, getState) => {
const {items} = getState().otherReducer;
dispatch(anotherAction(items));
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question