Can't return an object in reducer. react-redux

#1

I cant figure out why a simple reducer will not allow me to re-assin an object’s state.
I keep getting the error that saying that I cannot render a object as a child.

the code looks like this…

const countA = (state = {} , action) => {
  switch (action.type) {
    case 'ADD_A':
      return Object.assign({}, state, {countA: state.countA +1})
    default:
      return state;
  }
}

Also if I try to set the state = initialState , it gives me undefined, even though my initialState is in my store

#2

It’s hard to say without seeing the component, but is it possible you are trying to render a jsx component like

<div>{this.props.countA}<div>

If so, your reducer looks like it is set up as an object, like:

this.props.countA === { countA: 1 }

So you would either need to adjust the JSX component:

<div>{this.props.countA.countA}<div>

Or possibly tweak the reducer:

const countA = (state = 0 , action) => {
  switch (action.type) {
    case 'ADD_A':
      return state + 1;
    default:
      return state;
  }
}
#3

It had to do with the combine reducer function.
This is a onClick method, that is manipulating the state of a div.
So when I combined them in the reducer, I had to say …

div : action