React and Redux - Extract State Logic to Redux

Tell us what’s happening:

I’m not sure what the instruction tells me to do with the messageReducer function. I’ve read the hint but I still don’t understand the answer

Your code so far

// Define ADD, addMessage(), messageReducer(), and store here:
const ADD = "ADD"
const addMessage = (message) => { 
  return { type: ADD, message: message }
  }
const messageReducer = () => {

}

Your browser information:

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

Challenge Information:

React and Redux - Extract State Logic to Redux

Maybe go back to the Redux section and revisit the challenges that teach how to write a reducer.


  1. The reducer should have two parameters, the state and action.

  2. The state should have a default value of an empty array.

  3. The reducer should handle two cases, one where the action.type matches the ADD type, and a default case.

  4. When the action.type matches the ADD type, return a new array with the current state (spread/concat) and the payload on action.message.

  5. For the default case, return the state untouched.


1 Like