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

169
Views
How to prevent re-rendering upon adding new React component to form

TLDR: When I click a button to add a new element to a list of React components, it causes the entire list to rerender and lose the states in the process. How can I prevent this?


I have a list of components containing a textarea and a few other form elements.

Excerpt:

        <FormControl  as='textarea'  onChange={e => setTopicSents(e.target.value)}></FormControl>

As you can see, I have the form input stored in a state within the component itself. I have the "Topic" component defined within a "Topics" component which renders all of the text areas.

I have a button that, upon clicking, adds a new FormControl element to the "topics" array:

        const [topics, setTopics] = useState([0])
        function addNewTopic(){
            setTopics([...topics, topics+1])
        }

            <div>
                {topics.map((i)=>  <Topic></Topic> )}
                <Row style={{height: "3em"}}>
                <div>
                    <Button onClick={addNewTopic} className="cyan-btn">Add New 
                   Topic</Button>
                </div>
            </Row>
            </div>

The problem is that when I click the button to add a new form element, it causes the entire list to rerender and clears anything that the user has typed in the form. How can I change this so that either the states are preserved upon adding a new form element, or the addition of a new one does not cause the rerendering of the other form elements?

I hope that makes sense. Any help would be appreciated!

about 4 years ago · Juan Pablo Isaza
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!