Redux state clarification

Redux state clarification


I am a little confused on a Redux concept and would like some help clarifying it. May also do with React.
In Redux: Write a Counter with Redux challenge you have the state like so

const counterReducer = (state = 0, action) => {
  // code stuff here

But until this point through the React and Redux challenges states are made out to be Objects so wouldn’t it be like this?

const counterReducer = (state ={count: 0}, action) => {
  // code stuff here


i recently posted a similar question.

The difference here is that in Redux, certain properties in the overall state object are ‘exposed’ to the reducers and action creators (and these props are being referred to as ‘state’ in the parameters)

So in this case state=0 is actually a single property in the overall redux store state that we’ve allowed the reducer to see…


Yes, “exposed” that’s a good word for it.

In a real Redux app, you’d probably have something like this (from an app I’m working on):

import sortReducer from './sort'
import repsReducer from './reps'
import settingsReducer from './settings'

const rootReducer = combineReducers({
  sort: sortReducer,
  reps: repsReducer,
  settings: settingReducer,

Here each individual reducer is mapped onto a property on the store. For example the sortReducer reducer will get the property sort off the overall store In the FCC challenge, what is missing is

import counterReducer from './counter'

const rootReducer = combineReducers({
  counter: counterReducer

or something like that that is happening behind the scenes. Each reducer has its own property on the store.


Okay that is making more sense thank you for elaborating.