Rafalages
Rafalages

Reputation: 1426

Should I dispatch an action creator from inside another action

I have a function that set a value in the server and then depending of the result dispatch different actions.

actions.js file:

const fetchList = () => {
    return dispatch => {
        return api.list().then(list => {
            dispatch(receiveList(list));
        });
    };
};

...

const changeItems = () => {
    return dispatch => {
        return api.change()
        .then(() => {
            fetchList()(dispatch);
        })
        .fail(() => {
            messageService('Change Failed')(dispatch);
        });
    };
};

Am I doing something wrong or the fetchList()(dispatch) is the right thing to do?

Upvotes: 0

Views: 35

Answers (1)

lcarvalho
lcarvalho

Reputation: 39

You should take a look at redux-saga.

Upvotes: 1

Related Questions