I created a Youtube Player Frame and im using it inside of my Player React.Component. The first time where i call the Component, the Player loads normal but if I switch the component and go a second time to the Player Component, the Youtube Player Frame is not rendered...
const PlayerFrame = ({ videoId }) => { useEffect(() => { const tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; const firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); let player; (window as any).onYouTubeIframeAPIReady = () => { player = new (window as any).YT.Player('player', { height: 1000, width: 1000, videoId: videoId, }); }; return () => { (window as any).onYouTubeIframeAPIReady = null; }; }, [videoId]); return (<div><div id="player"></div></div> );};export default PlayerFrame;