Tell us what’s happening:
Is the guide correct for this issue? I’m reading the “Get a hint” guide page. Here is the link:
It shows the solution as returning defaultState if the action.type is not LOGIN. But the directions say to return the current state. Since defaultState is a const, it’s value will never change. I realize the guide code is simplistic code meant to educate, but returning defaultState seems wrong to me.
I believe the correct sample code should read:
// Same code above, only showing the reducer function.
const reducer = (state = defaultState, action) => {
// change code below this line
if (action.type === 'LOGIN') {
return {
login: true
}
} else {
return state;
}
// change code above this line
};
// Same code below.....
Your code so far
const defaultState = {
login: false
};
const reducer = (state = defaultState, action) => {
// change code below this line
if (action.type == 'LOGIN') {
return {login: true};
} else {
return state;
}
// change code above this line
};
const store = Redux.createStore(reducer);
const loginAction = () => {
return {
type: 'LOGIN'
}
};
If there is agreement that the guide could be improved, I can create a PR.
Thanks,
-Fred
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:64.0) Gecko/20100101 Firefox/64.0
.
Link to the challenge: