Junho  Park
Junho Park

Reputation: 257

In React Redux How to execute two or more actions

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?

Upvotes: 2

Views: 235

Answers (1)

Max Sindwani
Max Sindwani

Reputation: 1267

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).

Upvotes: 1

Related Questions