I don't know how to solve this. Challange: Redux: Use a Switch Statement to Handle Multiple Actions

Tell us what’s happening:

The store should be initialized with an object with an authenticated property set to false.

Dispatching loginUser should update the authenticated property in the store state to true.

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
}
dafault:
  return dafaultState;

}

// 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36.

Challenge: Use a Switch Statement to Handle Multiple Actions

Link to the challenge:

typo :point_up:
In addition, it’s a bad idea to return something outside the function, instead try returning state, meaning in default case state won’t change

1 Like

thanks so much, I feel so silly :sweat_smile: