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

175
Views
How to close a loader when iframe has loaded data from Api in react?

I want to display a loader on screen until iframe fully loads the content from Api..I am calling spotify api to display playlist

I am doing this way

//loader
import { RotatingLines } from 'react-loader-spinner';

//state
const [loadedlist, setloadedlist] = useState(true);

//component
return (
  <>
      
      {/* List Layout using spotify's embed */}
      
           {listLayout && (
        <div>
         {loadedlist ? <RotatingLines width="100" strokeColor="#FF5733" />  : 
          <div className="container">
            <iframe
              className="embedded_spotify_playlist"
              title="Spotify Playlist"
              onLoad={setloadedlist(false)}
              src={`https://open.spotify.com/embed/playlist/${playlistId}?utm_source=generator`}
              width="100%"
              height="500"
              frameBorder="0"
              allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture"
            />
          </div>
        }
        </div>
      )}

)

Currently I am able to display loader initially but It seem onload is not working, the loader does not disappear/closes even the content in iframe is loaded

How can I do this?

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

0

So, I did something like this on sandbox and it seems to work :

//state
const [loadedlist, setLoadedlist] = useState(false);

return (
  <>
    {!loadedlist && <RotatingLines width="100" strokeColor="#FF5733" />}
    <div>
      <div className="container">
      <iframe
          className="embedded_spotify_playlist"
          title="Spotify Playlist"
          onLoad={() => setLoadedlist(true)}
          src={`https://open.spotify.com/embed/playlist/37i9dQZF1DWVuV87wUBNwc?utm_source=generator`}
          width="100%"
          height="500"
          frameBorder="0"
          allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture"
        />
      </div>
    </div>
  </>)

I think it is the same problem as described here : Why do I need to pass an anonymous function into the onClick event?

For a more detailed answer, you can check 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!