Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

69
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!