redux-example icon indicating copy to clipboard operation
redux-example copied to clipboard

Dispatch GET_USER multiple times

Open DevAlien opened this issue 10 years ago • 2 comments

Hi, I've been playing around with your redux example and it is pretty cool, it does its job.

While checking the files, i run into the actions of the user and found that you dispatch the GET_USER 2 times, and the first time you don't do any actions. https://github.com/tommy351/redux-example/blob/master/src/actions/users.js Is there a reason for that?

Thanks for your time

DevAlien avatar Nov 24 '15 11:11 DevAlien

The first dispatch means the request started, it can be used on loading indicator for example. The second dispatch will be either success or failed. Here's the content of actions:

// Dispatch #1: Started
{
  type: 'GET_USER'
}

// Dispatch #2: Success
{
  type: 'GET_USER',
  payload: {
    // ...
  }
}

// Dispatch #2: Failed
{
  type: 'GET_USER',
  payload: {
    // ...
  },
  error: true
}

tommy351 avatar Nov 24 '15 15:11 tommy351

Ah ok, so why not calling them with different names? For me it does not make a lot of sense to use the same action for 2 different things

DevAlien avatar Nov 26 '15 16:11 DevAlien