Map Dispatch to Props -React/Redux

Map Dispatch to Props -React/Redux
0.0 0

#1

Tell us what’s happening:

It says dispatch is not defined

Your code so far


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

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) 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/


#2

Yes, because you do not define what dispatch is before using it.

Hint: No need to define dispatch, but if you read the following sentence of the challenge instructions, it tells you what you should do.

Write the function mapDispatchToProps() that takes dispatch as an argument, then returns an object.