Tell us what’s happening:
I have a doubt. The following code works correctly. But I don’t understand how the action argument gets the values from the defined actions, in the reducer method. I would need to use the dispatch method, wouldn’t I?
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36
.
Challenge: Use a Switch Statement to Handle Multiple Actions
Link to the challenge: