2

I have two redux actions which call as follows.

export function action1(params) {
  //This line is always called.
  return (dispatch) => {
    //This line is not called the second time.
    return MyApi.call1(params)
    .then(response => {
      // some logic
      return dispatch(someFunction1());
    })
    .catch(error => {
      throw(error);
    });
  };
}

export function action2(params) {
  return (dispatch) => {
    return MyApi.call2(params)
    .then(response => {
      // call the first API again
      action1();
      return dispatch(someFunction2());
    })
    .catch(error => {
      throw(error);
    });
  };
}

When the view is first loaded, action1 is called within the constructor of the view. Upon performing an action and triggering action2 in the same view, action1 needs to be called on action2's success to get the updated list from the server. Unfortunately, code breaks without any error when action1 is called the second time.

What am I missing here?

2
  • 5
    btw, you have not dispatched the action1 , like : dispatch(action1(params)) ; Feb 26, 2017 at 16:09
  • 1
    It worked. It was so silly of me. Can you post this as an answer so that I can accept it? Feb 27, 2017 at 5:59

1 Answer 1

2

You have not dispatched the action1.

dispatch( action1( params ) )

Invoking action1() without dispatch just returns a function. In order to get dispatch in returned function, you should dispatch that function. Then it will be caught by redux-thunk middleware. The middleware will pass dispatch and invoke function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.