Currently in the hint page we got this solution
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"
};
};
Then I have my own solution:
const defaultState = {
login: false
};
const reducer = (state = defaultState, action) => {
// Change code below this line
state.login = action.type === 'LOGIN'
return state
// Change code above this line
};
const store = Redux.createStore(reducer);
const loginAction = () => {
return {
type: 'LOGIN'
}
};
Meanwhile in the test case, it says:
Dispatching loginAction should update the login property in the store state to true.
In that case, my code should be able to pass the test since it updates the login
prop in the state
to true
. But it won’t, why?
Link to the challenge:
https://www.freecodecamp.org/learn/front-end-libraries/redux/handle-an-action-in-the-store