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

120
Visualizações
How to use the same lottie loading animation across site

I need some fresh eyes to tell me the approach they would take on this problem. I have a lottie loading animation component that I call whenever an API request is being made. It looks like this:

export default function LoadingAnimation() {
  useEffect(() => {
    lottie.loadAnimation({
      container: document.querySelector("#logo"),
      animationData: loadingAnimation,
    });
  }, []);
  return <div id="logo"></div>;
}

Where I would call:

{isLoading ? <LoadingAnimation /> : <OtherComponent />}

Being that the loading animation <div> has an id to place the loading animation on, what are the options for creating unique ID? Or is creating an unique ID not the way you would solve this? How would you solve this?

My thoughts are just to create a UUID, use a Date/Time stamp (unix time), or something similar to create the ID for the div but am I doing too much? Is there a more simple way of solving this? What are the common patterns for solving this sort of problem?

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

0

It seems that none of the suggestions I made would work as they produced multiple loading animations when the components rendered/re-rendered. Therefore, I used the useRef hook instead of an ID:

export default function LoadingAnimation() {
  const anime = useRef(null);
  
  useEffect(() => {
    lottie.loadAnimation({
      container: anime.current,
      animationData: clearpathLoadingAnimation,
    });
    return () => lottie.stop();
  }, []);

  return <div ref={anime}></div>
}

Solves the problem! More about the useRef hook here.

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