Im having trouble understanding middleware

Im having trouble understanding middleware.

Ex:

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

What is the point of introducing middleware? What exactly are asynchronous actions? What is there purpose and why use them.

Suggest you check the docs they are likely to be your best answer.



I am trying to read these and understand but still having trouble :frowning:

Its a bit confusing

What would happen here:

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);
    dispatch(receivedData(data))
  }
};

If you tried to do this without Asynch flow?

Did you test it?

I’m not a Redux expert and I honestly rarely use it. I’m sure there are others able to give you better answers than me.

I would suggest you test the code and play around with it to learn more. That is usually much more constructive than hypotheticals.

1 Like