Answer the question
In order to leave comments, you need to log in
What is the best way to pass dispatch to Redux (React)?
There is a function, and now a piece of code appears in it, which needs to be moved into a separate function. Well, the trick is that this is the action function. and in that section of code, dispatch is used. What is the best way to pass dispatch?
dispatch(subFunc(data)) or subFunc(dispatch, data);
const mainAction = (data) => {
return function (dispatch) {
subFunc(dispatch, data);
//или
dispatch(subFunc(data));
}
};
const subFunc= ((dispatch), data) => {
//......
dispatch(closeLoader())
//......
};
Answer the question
In order to leave comments, you need to log in
const func = data => (
dispatch => {
//......
dispatch(action());
//......
}
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question