Handling asynchronous actions

Tell us what’s happening:

I have been stuck on this test for a couple of days now
And the code seems ok to me ,but its not passing the last task

Your code so far


const REQUESTING_DATA = 'REQUESTING_DATA'
const RECEIVED_DATA = 'RECEIVED_DATA'

const requestingData = () => { return {type: REQUESTING_DATA} }
const receivedData = (data) => { return {type: RECEIVED_DATA, users: data.users} }

const handleAsync = () => {
return function(dispatch) {
  dispatch(requestingData());

  setTimeout(function(dispatch) {
    let data = {
      users: ['Jeff', 'William', 'Alice']
    }
    dispatch(recievedData(data));

  }, 2500);
};
};

const defaultState = {
fetching: false,
users: []
};

const asyncDataReducer = (state = defaultState, action) => {
switch(action.type) {
  case REQUESTING_DATA:
    return {
      fetching: true,
      users: []
    }
  case RECEIVED_DATA:
    return {
      fetching: false,
      users: action.users
    }
  default:
    return state;
}
};

const store = Redux.createStore(
asyncDataReducer,
Redux.applyMiddleware(ReduxThunk.default)
);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Use Middleware to Handle Asynchronous Actions

Link to the challenge:

There’s a typo in line:

dispatch(recievedData(data));

It should be:

dispatch(receivedData(data));
1 Like