Tell us what’s happening:
Can anyone tell me what’s the problem here please
Your code so far
// change code below this line
const LOGIN = 'LOGIN'
const LOGOUT = 'LOGOUT'
// change code above this line
const defaultState = {
authenticated: false
};
const authReducer = (state = defaultState, action) => {
switch (action.type) {
case 'LOGIN':
return {
authenticated: true
}
case 'LOGOUT':
return {
authenticated: false
}
default:
return state;
}
};
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/68.0.3440.106 Safari/537.36
.
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
Your switch cases and return type should make reference to the variable, not to a string.
e.g.
case LOGIN: //should be lOGIN, not 'LOGIN'
return {
authenticated:
}
Read the instructions more carefully. You’ve only done 1 of the 3 things that you need to do:
[1] Declare LOGIN and LOGOUT as const values and assign them to the strings ‘LOGIN’ and ‘LOGOUT’, respectively. Then, [2] edit the authReducer() and [3] the action creators to reference these constants instead of string values.
Tell us what’s happening:
Can anyone tell me what’s the problem here
Your code so far
// change code below this line
const LOGIN = 'LOGIN'
const LOGOUT = 'LOGOUT'
// change code above this line
const defaultState = {
authenticated: false
};
const authReducer = (state = defaultState, action) => {
switch (action.type) {
case 'LOGIN':
return {
authenticated: true
}
case 'LOGOUT':
return {
authenticated: false
}
default:
return state;
}
};
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/68.0.3440.106 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/redux/use-const-for-action-types/
i think you forgot to change the case lines to use the new consts you defined.
Quote block from the instructions:
then, edit the authReducer() and the action creators to reference these constants instead of string values.
1 Like
It should be like this.
// change code below this line
const LOGIN = 'LOGIN';
const LOGOUT = 'LOGOUT';
// change code above this line
const defaultState = {
authenticated: false
};
const authReducer = (state = defaultState, action) => {
switch (action.type) {
case LOGIN: // change this line
return {
authenticated: true
}
case LOGOUT: // change this line
return {
authenticated: false
}
default:
return state;
}
};
const store = Redux.createStore(authReducer);
const loginUser = () => {
return {
type: LOGIN // change this line
}
};
const logoutUser = () => {
return {
type: LOGOUT // change this line
}
};