Open rnnyrk opened 5 years ago
Hi! I published a new version that fixes the bundling of the package.
Unfortunately it seems like the <Script />
tag can't be injected properly because of this issue: https://github.com/facebook/react/issues/14780
What you can do instead is add a <script src="https://sdk.scdn.co/spotify-player.js" />
tag to the head of the document yourself instead, and not use the <Script />
tag, for now :(
@niekert Could you update the readme to show how to get a working example of this running?
Thank you.
I couldn't fix it with the provided solution by @niekert either. Now trying to build my own hook based on this repo and this SO solution. Not completely there, but it seems to work so far.
I haven't had time to update the repo yet with a working version, but I am using a similar hook in one of my projects. You can check here for inspiration on how to inject the spotify script: https://github.com/niekert/FissList/blob/master/packages/client/src/hooks/spotifyWebSdk.tsx
Also got it working now. Got almost the same setup, but with an authentication prop;
React.useEffect(() => {
if (authenticated) {
window.onSpotifyWebPlaybackSDKReady = () => {
playerRef.current = new window.Spotify.Player({
name: 'Spotify Together',
getOAuthToken: (cb) => {
console.log('accessToken', localStorage.getItem('accessToken'));
const token = localStorage.getItem('accessToken');
cb(token);
},
});
setIsReady(true);
};
}
if (!window.Spotify) {
const scriptTag = document.createElement('script');
scriptTag.src = 'https://sdk.scdn.co/spotify-player.js';
document.head.appendChild(scriptTag);
}
}, [authenticated]);
Hi,
I get the following error after using your package.
My Root file is as followed:
My Webpack has the following loaders:
Any idea what's the issue?