0
I was trying to link the Spotify API script to the React component, but when I use the "window.onSpotifyWebPlaybackSDKReady" function it shows the error:"Property onSpotifyWebPlaybackSDKReady does not exist on type 'Window & typeof globalThis"as if he didn’t recognize the script. How can I fix this ?
import React, { useEffect, useState } from 'react';
function SpotifyPlayer() {
useEffect(() => {
const script = document.createElement("script");
script.src = "https://sdk.scdn.co/spotify-player.js";
script.async = true;
document.body.appendChild(script);
window.onSpotifyWebPlaybackSDKReady = () => {
// do your spotify magic here.
}
}, []);
}
export default SpotifyPlayer;
NOTE: the main HTML is in one folder and the component is in another, but I have tried to put the script tag in the main html body and yet it did not recognize the function in the component.