Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

71
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda