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

162
Views
How to add loader to website while Axios is getting data?

I'm getting my data at very slow rate so when i open my website first time it takes some times untile showing all the product. So i want to add a loader untile my data is fully loaded.

i used custom Hook to load data

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

One way of doing this, that I like, and is very straight forward is by adding conditional statements, meaning that if the data passed as a prop is currently undefined return <div>Loading.....</div> in opposite case return the JSX containing the prop data.

If you don't do this, React will show an error. This is because when fetching there is a time that the data is undefined and if React tries to do something with it before hand, it finds nothing. This conditions are a way to tell React when is a good time to access the data.

export default function MyComponent({someData}){

  if(!someData) return <div>Loading.....</div>
  else{
     return <div>{someData}</div>
  }
}
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!