Map Dispatch to Props help

Map Dispatch to Props help
0

#1

Tell us what’s happening:
This code is working but I want to know can I write mapDispatchToProps function like this:

function mapDispatchToProps(dispatch){
return{
dispatch(addMessage(newMessage))
}
}

and call it component props like:

this.props.dispatch.addMessage(newMessage);

is it correct?

Your code so far


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

// change code below this line
function mapDispatchToProps(dispatch) {

  return {
    submitNewMessage :(newMessage)=>{ dispatch(addMessage(newMessage)) }   
  }

}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react-and-redux/map-dispatch-to-props