useSelector not updating when store has changed in Reducer. ReactJS Redux

NOTE: you better start using redux-toolkit to prevent references
in you code its a better and almost a must way for using redux

the problem your facing is very common when handling with objects,
the props do not change because you’re changing an object property but the object itself does not change from the react side.

even when you’re giving it a whole new object
react doesn’t see the property object change because the reference stays the same.

you need to create a new reference like this:

Object.assign(state.data,data);

return {
  ...state,
  data: { 
    ...state.data,
    Endereco: action.payload.logradouro,
    Bairro: action.payload.bairro,
    UF: action.payload.uf,
    Cidade: action.payload.cidade                    
  }
}

to add more you can learn about the Immer library that solves this
problem.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)