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

255
Vistas
useEffect does not get triggered when a dependence value changes from 1 to 0

I'm so confused about the behaviour of useEffect in the following case:

Code snippet:

const verticesCount = selectionProvider.verticesSelectionProvider.count;
console.log('RENDER ---> COUNT = ', verticesCount);
useEffect(() => {
    console.log('EFFECT : COUNT UPDATED ---> COUNT = ', verticesCount);

    return () => console.log('USEEFFECT:CLEANUP');
}, [verticesCount]);

The console:

1: RENDER ---> COUNT =  0 
2: EFFECT : COUNT UPDATED ---> COUNT =  0
3: RENDER ---> COUNT =  1
4: USEEFFECT:CLEANUP
5: EFFECT : COUNT UPDATED ---> COUNT =  1
6: RENDER ---> COUNT =  0
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Without a better example it is difficult to tell what is the problem.

My guess is that verticesCount didn't change.

For example verticesCount was: 1, changed to 2, changed to 1, then changed one more time to 1

But because the state value didn't change the last time the useEffect didn't trigger. One possible solution:

  • create a bool state: const [update, setUpdate] = useState(false);
  • in your verticesSelectionProvider toggle setUpdate(!update) every time vertices changed
  • in useEffect() listen for update instead of verticesCount
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