Redux - Use a Switch Statement to Handle Multiple Actions

Tell us what’s happening:
Describe your issue in detail here.
Hello, in the default case of my switch statement I am returning state, but in the solution they return defaultState. My method passes all of the tests, but could someone please explain the correct solution? state and defaultState seem to be the same value and that this is a minor detail, but since these are objects I am worried about object reference errors.

Your code so far

const defaultState = {
  authenticated: false
};

const authReducer = (state = defaultState, action) => {
  // Change code below this line
    switch (action.type) {
      case 'LOGIN':
        return { authenticated: true };
      case 'LOGOUT':
        return { authenticated: false };
      default:
        return state;
    }
  // Change code above this line
};

const store = Redux.createStore(authReducer);

const loginUser = () => {
  return {
    type: 'LOGIN'
  }
};

const logoutUser = () => {
  return {
    type: 'LOGOUT'
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36

Challenge: Redux - Use a Switch Statement to Handle Multiple Actions

Link to the challenge:

That’s a good question. I would also think you should just return state since that’s the name of the parameter–the only time state would NOT equal defaultState is if it’s already been changed. I’ll be curious to hear the answer, if it isn’t just an accident.

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