Redux - how to call an action creator from inside another activity creator?

I have the following action creator:

export function foo(param) {
    ...
}

      

and I want to call it from the adjacent action creator (in the same file) like this:

export function bar(param){
    return (dispatch, getState) => {
        dispatch({
            type: ATYPE.SET_DO_THIS_BEFORE_FOO,
            payload: param
        });

        foo(param);
    }
}

      

but the action creator is foo

not triggered from within bar

. Is there a way to do this?

+3


source to share


1 answer


As per your example, it seems like you are already using redux-thunk

. If that's the case, the only thing you forget is to dispatch the action your action creator created:



dispatch(foo(param));

      

+5


source







All Articles