handleAsync not dispatching. Please what is wrong with the code

Tell us what’s happening:
Describe your issue in detail here.

  **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 request action here
  dispatch(requestingData());

  setTimeout(function() {
    let data = {
      users: ['Jeff', 'William', 'Alice']
    }
    // Dispatch received data action here
dispatch(receivedData());
  }, 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 (Linux; Android 10; TECNO B1g) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.96 Mobile Safari/537.36

Challenge: Use Middleware to Handle Asynchronous Actions

Link to the challenge:


// dispatch received data action here
dispatch(receivedData(data));
}, 2500);

1 Like

Thanks, I can see the source of error.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.