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

246
Visualizações
How to tell if a React functional component has been rendered in code?

I am trying to add some logging to see how much time it takes to render a functional component in React. The tricky part to me is how to actually tell when the component has been rendered. By "rendered", it means the user can see it in the front end (all parts in that component should be displayed). I am trying to use useEffect to achieve this, as it can tell when the component is mounted.

The code is something like below:

function showComponent() {
   console.log('start rendering....start timer');
   console.log(new Date().getTime());
   
   setStoreViewState('foobar');
}

observer(function Component() {
   React.useEffect(() => {
     console.log('rendering complete....stop timer');
     console.log(new Date().getTime());
 }, []);
   ......
   const thingsToShow = getStoreViewState();
   return (<div>{thingsToShow}</div>)
}

I am wondering if this is an accurate way to achieve this. Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

According to the docs, the useEffect with no dependency means that it has finished rendering.

https://reactjs.org/docs/hooks-effect.html

Also, don’t forget that React defers running useEffect until after the browser has painted, so doing extra work is less of a problem.

The quote above is from the docs.

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