Redux: View (Render) is not Updated after State Change - No Obvious Mutations made in Reducer

Created on 29 Sep 2017  ·  5Comments  ·  Source: reduxjs/redux

I would like to submit a:

  • [x] Bug
  • [ ] Feature

_It most probably is my mistake, but that's why I'm here. I'm stuck and I don't know what it is._

Redux doesn't update/re-render the components state, but the Redux' state updates as it should.
There are no obvious mutations from the perspective I'm seeing it. I've used so far:

  • Object.assign({}, source)
  • slice(startIndex) // Definitely Does not work. Tried it on JSFiddle and when I changed it to Object.assign() it worked.
  • ES6 Spread Operator
    etc.

And nothing worked.

Code (md & gists) :

Sub-Reducer

export default (state = [], action) => {
  switch (action.type) {
    case ADD_COMPONENT:
      if (state[action.id]) {
        console.error('Error: Cannot add component, id already exists');
        return state;
      } else {
        return {
          ...state,
          [action.id]: action.obj
        }
      }
    case 'debug':
      console.log('debug', state[action.id]);
      return state;

    default:
      return state;
  }
};

React Component https://gist.github.com/Eksapsy/4f0b348765ba648a6c62baa249d4f756
Actions https://gist.github.com/Eksapsy/31c1c84e0b5975a5a0352d24af75419c

The root reducer does not have any problems, I'm 110% of that. I'm using it the same way with this reducer as I do with my other _Working_ reducers

_I wish I could provide a demo in JSFiddle, but I can't reproduce the bug. It's just different code. Actually, when I use some of the code in JSFiddle the code works, but it isn't the same code as in my project's_

react-redux: 5.0.6",
redux: 3.7.2,
redux-thunk: 2.2.0,

Most helpful comment

Hey @markerikson. I just joined after a long day in this issue to just delete my Comment before anyone sees it because it was too rude and I'm sorry I brought my personal problems here. :) Timdorr actually helped me very much, and I thanked him in my first comment, even if this was not my problem but as you said it's not a support forum. Although it just broke my mind control at some moment the fact that he jumped to conclusions and closed instantly the issue, I definitely shouldn't have acted like that. Dammit.

Hm, your suggestions also helped much! Thanks!

Have a happy rest of your day and thank you for supporting this beautiful product, guys!
I'll drink a beer for you!

All 5 comments

The truth is that I got Router in my Project.
I Injected withRouter in every possible Component that has to do with the specific Component and itself as well. And didn't work.

But thank you, I didn't know about the issue you sent me.

Do I have to make another issue with the same content now or what? You closed it without considering if that's my issue or not. And since no one answering 1 day after you closed the issue, I consider making that move.
And I don't see anywhere a sign that I'm using Router. So how were you so sure that this was my issue and you instantly closed it?

Yeah, the Router thing was probably jumping to conclusions a bit.

However, a few other thoughts.

First, this _is_ a bug tracker, not a support forum. You should try posting this question over on Stack Overflow or asking it in the Reactiflux chat channels. There will be more people available who can see the question and try to help.

It's not clear from the sample code you linked or the description you gave what exactly you mean by "Redux isn't updating the component's state".

Copying values from props into an instance field like this.reduxState is a very odd pattern, and is probably not a good idea.

It looks like you're actually including the component instance itself in the action, and inserting that instance into the store. That is a bad idea - please do not do that.

It also looks like your reducer is defining its initial state as an array, but then trying to update it as if it were an object. That won't work properly.

If you are trying to keep per-component state in a Redux store, there's many existing libs that implement that capability - you should try using one of those instead (like redux-ui, react-redux-local, or lean-redux).

Hey @markerikson. I just joined after a long day in this issue to just delete my Comment before anyone sees it because it was too rude and I'm sorry I brought my personal problems here. :) Timdorr actually helped me very much, and I thanked him in my first comment, even if this was not my problem but as you said it's not a support forum. Although it just broke my mind control at some moment the fact that he jumped to conclusions and closed instantly the issue, I definitely shouldn't have acted like that. Dammit.

Hm, your suggestions also helped much! Thanks!

Have a happy rest of your day and thank you for supporting this beautiful product, guys!
I'll drink a beer for you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vraa picture vraa  ·  3Comments

vslinko picture vslinko  ·  3Comments

mickeyreiss-visor picture mickeyreiss-visor  ·  3Comments

olalonde picture olalonde  ·  3Comments

caojinli picture caojinli  ·  3Comments