React and Redux - Map Dispatch to Props

Tell us what’s happening:

I am having trouble understanding dispatch here. I thought in order to use dispatch, it had to be done like this: store.dispatch(action());
But in this lesson, we write it like this: dispatch(action()). Please explain why, thank you.

Your code so far

const addMessage = (message) => {
  return {
    type: 'ADD',
    message: message
  }
};

// Change code below this line
const mapDispatchToProps = (dispatch) =>{
  return {
    submitNewMessage: (message)=>{
      dispatch(addMessage(message))
    }
  }
}

Your browser information:

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

Challenge Information:

React and Redux - Map Dispatch to Props

Hi @jobanibusiness

Behind the scenes, React Redux is using Redux’s store.dispatch() to conduct these dispatches with mapDispatchToProps() . This is similar to how it uses store.subscribe() for components that are mapped to state .

This lesson is showing another way to dispatch an action.

Happy coding

1 Like

So we have two ways to dispatch? :
store.dispatch(action);
and
dispatch(action);