Switch Statement in Redux

Could somebody explain me why my code not working?

  **Your code so far**

const defaultState = {
authenticated: false
};

const authReducer = (state = defaultState, action) => {
// Change code below this line
switch(action.type){
case loginUser:
return {authenticated:true};
case logoutUser:
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Challenge: Use a Switch Statement to Handle Multiple Actions

Link to the challenge:

Solved, i changed loginUser to ‘LOGIN’ & logoutUser to ‘LOGOUT’.

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
};

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