Answer the question
In order to leave comments, you need to log in
Redux thunk, where does dispatch come from in an action?
where can we use dispatch? this is a method of the store, why then we call not in its context? in the dispatch component comes through the context, and where it comes from in the action from the example below which is from the redux-thunk docks, for me it looks like it comes from window.
const INCREMENT_COUNTER = 'INCREMENT_COUNTER';
function increment() {
return {
type: INCREMENT_COUNTER
};
}
function incrementAsync() {
return dispatch => {
setTimeout(() => {
// Yay! Can invoke sync or async actions with `dispatch`
dispatch(increment());
}, 1000);
};
}
Answer the question
In order to leave comments, you need to log in
It comes from the redux-thunk
middleware Let's
look at the source code:
function createThunkMiddleware(extraArgument) {
return ({ dispatch, getState }) => next => action => {
if (typeof action === 'function') {
return action(dispatch, getState, extraArgument);
}
return next(action);
};
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question