Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
ReactJs component does not get updated/rerendered when the store is updated

I have this component that shows list of education items added by the user where each time represents where he studied and for how long...etc:

class EducationItems extends Component {
  render() {
    const education = !!this.props.profile ? this.props.profile.education : [];
    return (
      <div>
        {!!education &&
          education.map((education_element_data, i) => {
            console.log(
              "🚀 ~ file: EducationItems.js ~ line 26 ~ EducationItems ~ education.map ~ i",
              i
            );
            return (
              <EducationItem
                number={i}
                educationElementData={education_element_data}
              />
            );
          })}
      </div>
    );
  }
}

const mapStateToProps = (state) => ({
  profile: state.profile.profile,
});

const mapDispatchToProps = {};

export default connect(mapStateToProps, mapDispatchToProps)(EducationItems);

It is connected to the profile value in the store as you can see:

const mapStateToProps = (state) => ({
  profile: state.profile.profile,
});

When the user adds education, I get the new list of all education(s) he added and I try to updated in the UI. So in the reducer I have this:

profileReducer.js

const initialState = {
  profile: null,
};

   case ADD_EDUCATION:
      let updated_profile_with_new_education = state.profile;
      updated_profile_with_new_education.education =
        action.payload.updated_education;
     
      return {
        ...state,
        profile: updated_profile_with_new_education,
      };

The problem after the user adds an education successfully, the EducationItems component does not get rerendered.

It seems that it is not detecting the change in store.state.profile.education for some reason.

I thought that updating anything in store.state.profile would get it rerendered since it is connected to that value in the store.

Any idea what's going on?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda