2

In React-redux project, sometimes we need to execute two actions.

For example,

// I have to both 
handleAddItem(){
  this.props.actions.addItem(); // working
  this.props.actions.updateItemList(); // not working
}

Above code is not working. It just seems to be executed first action addItem(). updateItemList() is not working.

But I found hack to execute both actions,

handleAddItem(){
  this.props.actions.addItem(); // working
  setTimeout(()=>{
    this.props.actions.updateItemList(); // It's working
  }, 1000);
}

Is there accurate code to execute 2 more actions?

Junho Park
  • 247
  • 1
  • 3
  • 10

1 Answers1

1

To add to my comment earlier, How to dispatch a Redux action with a timeout? explains a widely used solution to your problem. As for differentiating between sync and async actions, simply return either an object (synchronous support) or a function (asynchronous support).

Community
  • 1
  • 1
Max Sindwani
  • 1,267
  • 7
  • 15