Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!