Hello campers,
I just did a Redux challenge and I realize that the addToDo
function takes an argument called todo
which then added to the object that will be returned.
What I want to know is by the way the parameter is added to the object, is it supposed to be a key-value pair, or consider as a key without value? Because what I did was passing a string "Reading"
to the function and the program still works and the challenge is solved. Is it supposed to be key-value pair like todo: "Reading"
or something other than that?
Any answer would be appreciated. Thank you.
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
default:
return state;
}
};
const addToDo = (todo) => {
return {
type: ADD_TO_DO,
todo
}
}
const store = Redux.createStore(immutableReducer);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
.
Challenge: Never Mutate State
Link to the challenge: