Please i need help with this challenge

Tell us what’s happening:
Describe your issue in detail here.
I did this challenge but have issue with solving this ( Dispatching handleAsync should dispatch the data request action and then dispatch the received data action after a delay.)

  **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

  }, 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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36

Challenge: Use Middleware to Handle Asynchronous Actions

Link to the challenge:

Below the comment // Dispatch received data action here

You have to call dispatch with receivedData() passing the data as an argument to it (it being receivedData()).

Thank you, But still i got stuck on it, can’t still solve it.

We have to see your code.

It is exactly the same code as the other dispatch you just use the receivedData function and pass it the data object as an argument.

Example:

dispatch(someFn(someData))

i have done it. thanks

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