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

171
Vistas
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
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