Redux - Combine Multiple Reducers

**T * The counterReducer should increment and decrement the state.

  • Failed:The authReducer should toggle the state of authenticated between true and false.

  • Failed: The store state should have two keys: count, which holds a number, and auth, which holds an object. The auth object should have a property of authenticated, which holds a boolean.:**
    I have implemented it in difference ways and it kept showing me this same answer, error.

**Your cconst INCREMENT = ‘INCREMENT’;
const DECREMENT = ‘DECREMENT’;

const counterReducer = (state = 0, action) => {
switch(action.type) {
case INCREMENT:
return state + 1;
case DECREMENT:
return state - 1;
default:
return state;
}
};

const LOGIN = ‘LOGIN’;
const LOGOUT = ‘LOGOUT’;

const authReducer = (state = {authenticated: false}, action) => {
switch(action.type) {
case LOGIN:
return {
authenticated: true
}
case LOGOUT:
return {
authenticated: false
}
default:
return state;
}
};

// Define the root reducer here
const rootReducer = Redux.combineReducers({
count: counterReducer,
auth: authReducer
});

ode so far**

const INCREMENT = 'INCREMENT';
const DECREMENT = 'DECREMENT';

const counterReducer = (state = { counter: 0 }, action) => {
  switch (action.type) {
    case "INCREMENT":
      return {
        counter: state.counter + 1,
      };
    case "DECREMENT":
      return {
        counter: state.counter - 1,
      };
    default:
      return state;
  }
};

const LOGIN = 'LOGIN';
const LOGOUT = 'LOGOUT';

const authReducer = (state = {authenticated: false}, action) => {
  switch(action.type) {
    case LOGIN:
      return {
        authenticated: true
      }
    case LOGOUT:
      return {
        authenticated: false
      }
    default:
      return state;
  }
};


// Define the root reducer here
const rootReducer = Redux.combineReducers({
  count: counterReducer,
  auth: authReducer
});


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.47

Challenge: Redux - Combine Multiple Reducers

Link to the challenge:

You have changed and removed code you were not asked to. Reset the challenge.

The only change needed is this part.

const rootReducer = Redux.combineReducers({
  count: counterReducer,
  auth: authReducer
});

And you still need the createStore from the initial starting code after the combineReducers code.

const store = Redux.createStore(rootReducer);
2 Likes

If I reset the challenge, I have to start again from the beginning

You can just copy and paste the code from this thread.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.