Tell us what’s happening:
I’m trying to complete some Redux challenges using the es6 spread operator feature and It seems to break something in the page, because tests are not running anymore,
Note that the same code with the horrible “stringify + parse” approach works fine.
Hi, just as a reference to anyone who gets stuck on this in the future, the code below passes the tests since they only look for this one property, not the entire state object (assuming it contained multiple fields, not just ‘authenticated’):
switch(action.type) {
case 'LOGIN':
return {authenticated: true};
case 'LOGOUT':
return {authenticated: false};
default:
return state;
}
I like how you used the spread operator, though.
May I ask, what did you mean by “stringify + parse”?
i think it’s wrong pbrook72. that was my initial answer until i saw the comments written before you, see …what you just wrote means that every time an action that has nothin to do with those reducers is dispatched and those 2 will run again, it will run a false authentication value instead of the current…so the right thing to do is to return the current state which in the reducer function is an argument called “state”.