Redux - Never Mutate State - solution - what is this data type ?!

Tell us what’s happening:
I understand the challenge, but what is this data structure here in the solution ?

const addToDo = (todo) => {
  return {
    type: ADD_TO_DO,
    todo
  }
}

I don’t understand what is this. In my solution I wrote:

const addToDo = (todo) => {
  return {
    type: ADD_TO_DO,
    todoi: todo
  }
}

because that’s the proper javaScript object. But this first one provided in the solution ? No clue, there was nothing about this type of data previously and I don’t understand how it works here…

Your code so far

const ADD_TO_DO = 'ADD_TO_DO';

// A list of strings representing tasks to do:
const todos = [
  'Go to the store',
  'Clean the house',
  'Cook dinner',
  'Learn to code',
];

const immutableReducer = (state = todos, action) => {
  switch(action.type) {
    case ADD_TO_DO:
      // Don't mutate state here or the tests will fail
      return state.concat([action.todoi])
    default:
      return state;
  }
};

const addToDo = (todo) => {
  return {
    type: ADD_TO_DO,
    todoi: todo
  }
}

const store = Redux.createStore(immutableReducer);

Your browser information:

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

Challenge: Redux - Never Mutate State

Link to the challenge:

I believe that is using object property shorthand:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.