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

70
Visualizações
Re-Render only a particular child

I am building a dynamic form and as of now, my component hierarchy is as follows:-

App
  Caseform
    DynamicFormBuilder
      Context.Provider
        Patients
          Patient key = "patient_1"
            ComponentCreator key = "patient_1_1"
              Textbox
            ComponentCreator key = "patient_1_2"
              Textbox
            ComponentCreator key = "patient_1_3"
              Textbox
          Patient key = "patient_2"
            ComponentCreator key = "patient_2_1"
              Textbox
            ComponentCreator key = "patient_2_2"
              Textbox
            ComponentCreator key = "patient_2_3"
              Textbox

As of now, I have hardcoded JSON data in caseform but eventually, it will come from the fetch call. As soon as DynamicFormBuilder receives the caseform metadata, it creates states out of it.

I am maintaining state at caseform level even for its child. I thought of doing it that way because the requirement was to support patch save(send only changed data to the backend on save button press). If anybody knows of a better way of doing this, please let me know.

I am passing in a function using context API to child components so that they can update the state in DynamicFormBuiler.

The issue I am facing is that let's say even if the user edits one textbox, the whole Dynamic form gets rendered.

I have gone through a lot of answers on StackOverflow that advise on using the shouldComponentUpdate lifecycle method, but I am not able to figure out how I will use it here.

I am adding a link to the sandbox and in the console, you can see that if a user edits a field all the things are rendered again.

CodeSandbox Link

Expected Behavior:- What I am looking for is for example:- if user-edited only one textbox say in patient 1 then only that textbox gets re-rendered again

This is my first time using react. I apologize in advance if someone feels I have not done enough research, I have read through a lot of questions but still facing some challenges, any help will be really appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you wrap each component in the React.memo() HOC, this should prevent excessive rerenders.

https://reactjs.org/docs/react-api.html#reactmemo

-Edit-

Yes it works with class components too.

e.g.

const MyComponent = React.memo(class extends React.Component {
  render () {
    return <h1>TEST</h1>
  }
});
about 4 years ago · Juan Pablo Isaza Relatório
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