score:5

Accepted answer

don't combine them into booksmangereducer. instead, just export them all as named exports and combine all the reducers at once:

export { 
  books, 
  employees, 
  employeeslist, 
  bookspagination, 
  booksstate 
};

then import them all:

import { 
  books, 
  employees, 
  employeeslist, 
  bookspagination, 
  booksstate 
} from './booksmanagereducer'

then combine them all individually with combinereducers:

combinereducers({
  books, 
  employees, 
  employeeslist, 
  bookspagination, 
  booksstate,
  companyid,
  routing: routerreducer
});

combinereducers uses the keys of the passed object to construct state. this will give the desired hierarchy.

another way which is similar to what you're doing could be exporting an object containing all the reducers themselves, then import the object and spreading it:

export default {
    //books, employees, etc.
};

then:

import reducers from './booksmanagereducer';

finally:

combinereducers({
  ...reducers,
  companyid,
  routing: routerreducer
});

Related Query

More Query from same tag