Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const defaultState = {
- authenticated: false
- };
- const authReducer = (state = defaultState, action) => { //state is set to the default object using ES6 syntax. It's accepting the state, and the action.
- // change code below this line
- switch (action.type) { //switches on the values of the action that the reducer is accepting. Changes the state based on the result.
- case 'LOGIN':
- return {authenticated:true};
- break;
- case 'LOGOUT':
- return {authenticated:false};
- break;
- default:
- return state;
- break;
- }
- // change code above this line
- };
- const store = Redux.createStore(authReducer); //passing the reducer into the createStore is telling the store what function is used to update the state.
- const loginUser = () => {
- return {
- type: 'LOGIN'
- }
- };
- const logoutUser = () => {
- return {
- type: 'LOGOUT'
- }
- };
Add Comment
Please, Sign In to add comment