Tell us what’s happening:
My console.log is giving me the correct answer from what I understand but it still won’t pass this test “should update the property status in state to online and should NOT mutate state.” Can anyone see why? Thank you.
Your code so far
const defaultState = {
user: 'CamperBot',
status: 'offline',
friends: '732,982',
community: 'freeCodeCamp'
};
const immutableReducer = (state = defaultState, action) => {
switch(action.type) {
case 'ONLINE':
// don't mutate state here or the tests will fail
const newObject = Object.assign({}, state, action);
newObject.status = action.type.toLowerCase();
console.log(newObject);
console.log(defaultState);
return newObject;
break;
default:
return state;
}
};
const wakeUp = () => {
return {
type: 'ONLINE'
}
};
const store = Redux.createStore(immutableReducer);
//store.dispatch(wakeUp());
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/redux/copy-an-object-with-object-assign/