Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

256
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda