Map Dispatch to Props - not sure what the error is asking for

Tell us what’s happening:
I m getting the following error message. However in my test code (two console.log statement at the bottom), it shows the code is able to return a message to the dispatch function. I am not sure what I am missing here.

“Dispatching addMessage with submitNewMessage from mapDispatchToProps should return a message to the dispatch function.”

Your code so far


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

// change code below this line
function mapDispatchToProps(dispatch ) {
  return {
    submitNewMessage :dispatch 
  };
}

console.log( addMessage('msg1').message );
console.log( mapDispatchToProps(addMessage).submitNewMessage('msg2').message  );

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0.

Link to the challenge:

In mapDispatchToProps function you want some property that calls the dispatch method with some action creator and some action data.

Or in other words you want your object props to be functions that calls dispatch with some actions.

const mapDispatchToProps = dispatch => ({
  myProp: someValue => dispatch(myAction(someValue))
})

// equivalent to
function mapDispatchToProps(dispatch) {
  return {
    myProp: function(someValue) {
      // call dispatch with an action creator
      dispatch(myAction(someValue))
    }, 
  }
}

Hope it helps :smile: