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

150
Visualizações
make useEffect run before render is completed OR an alternative to use Effect

I have functions that I want to execute when state changes. But I don't want them to wait until render is completed, since it doesn't depend on the rendered DOM.

Is there a way to execute a function when certain dependencies change just like useEffect, but not wait until rendering is completed?

I was thinking to use useMemo or useCallback, but it seems not an ideal solution since it uses memory.

Is there a direct solution for this?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

If the code that you want to execute may call state setters itself, which results in undesirable flickering, you can switch out useEffect for useLayoutEffect, which runs after the DOM mutations from the render have occurred, but before the browser has repainted the screen. As a result, if any state setters get called, and the component renders again, the user won't see the component rendering twice, because the updates all occur before the screen repainting (except for the very last one).

useLayoutEffect has the exact same function signature as useEffect, so making the changes should be quite trivial.

about 4 years ago · Santiago Gelvez 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