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

182
Vistas
Does React re-executes useState after setState?

If setState trigger a re-rendering of the component, and useState executes for every render, then why does it updates the old value if the initialization is going to be re-executed?

for example, if i have a counter set to 0 (useState(0)) and i modify the state of that counter via setState to 1, that will trigger a re-render therefore useState will be executed again and therefore the value should be zero again, but that does not happen(fortunately) and i don't know why?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

That's how this react hook is implemented.

The value parameter is ignored on subsequent renders by react. It will only be set to this value on the initial render.

You can read more about the internals of React from authors that went inside the code to check it or check the internal code yourself.

Here's one that I've found: https://www.newline.co/@CarlMungazi/a-journey-through-the-usestate-hook--a4983397

about 4 years ago · Juan Pablo Isaza Denunciar

0

useState is triggered on every render yes. But the value is disregarded after the very first render.

From the docs:

You might be wondering: why is useState not named createState instead? “Create” wouldn’t be quite accurate because the state is only created the first time our component renders. During the next renders, useState gives us the current state.

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