Combine Multiple Reducers help i'm stuck

Tell us what’s happening:

Your code so far


const 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;
  }
};

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

const store = Redux.createStore(rootReducer);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/redux/combine-multiple-reducers

Try to step back a bit and read the instructions. Here is how to create a combined reducer and assign it to a variable called rootReducer per the instructions

const rootReducer = Redux.combineReducers({
  auth: authenticationReducer,
  notes: notesReducer
});

And here is how you assigned the output to rootReducer

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

The method of combineReducers() provided by redux takes only one object as an argument, that object has a key-value pair of the names you want to assign to your unit reducers as the keys and the unit reducers themselves as values. The method then outputs one big reducer to hold all state information.
state and action are thus only passed to your individual unit reducers only, the combiner does not need that information passed to it as arguments since it already has that info available in the object passed to it.

1 Like

sorry still i didn’t get the answer

ok,let me try to explain it.U should be familiar by now with store .How do u use it ? .

1-create a constant ; const store
2-use Redux to get a method u need from it which is createStore
3-Finally u put your reducer in that method

Now,rootReducer is exactly the same thing but instead of createStore u want combineReducers
and instead of giving your method a reducer , you will give it an object .again it is EXACTLY DONE IN THE SAME WAY .