Problem on Never Mutate State

Problem on Never Mutate State
0

#1

Tell us what’s happening:

I pushed the item in a copy of array but something got wrong.

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].push(action.todo);
    default:
      return state;
  }
};

// an example todo argument would be 'Learn React',
const addToDo = (todo) => {
  return {
    type: ADD_TO_DO,
    todo: "Learn react"
  }
}

const store = Redux.createStore(immutableReducer);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; 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/redux/never-mutate-state/


#2

Push doesn’t return the array, it returns the new length of the array


#3

I tried also return […state, action.todo] but it doesn’t work


#4

I think the addToDo function should use its argument and not hardcode the to-do

I’m not at a pc right now to check