My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

How do reducers in Redux get their own part of state?

Iván Portilla's photo
Iván Portilla
·Sep 12, 2016

Hi everybody,

I am currently learning Redux after gaining some React fundamental concepts, I am watching Learn Redux video series from Wes Bos, which is an amazing resource!

I have the next question, in that tutorial we have a store with:

  • Posts
  • Comments

Supposedly every "part" of the store should have a "reducer", so we have a "comments" reducer and a "posts" reducer, which are merged inside index reducer with combineReducers. Everything is okay until now, but here comes my question, each reducer receives a part of the state and it is precisely either the posts array, or the comments array. How do the reducers know which part of the state should they use? Where does this happen?

This is from Redux docs:

Note that each of these reducers is managing its own part of the global state. The state parameter is different for every reducer, and corresponds to the part of the state it manages.

Greetings!