ibrahimcesar / react-lite-youtube-embed

πŸ“Ί β€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Ž< A private by default, faster and cleaner YouTube embed component for React applications />
https://www.npmjs.com/package/react-lite-youtube-embed
MIT License
263 stars 40 forks source link

Trouble using both ref and onIframeAdded #100

Open RapidOwl opened 9 months ago

RapidOwl commented 9 months ago

Describe the bug

I'm relatively inexperienced with React and this is my first attempt at using ref so it's entirely possible this is my fault.

To Reproduce

Here's my code extracted for readability:

const videoRef = useRef<HTMLIFrameElement>(null);

useEffect(() => {
  if (videoRef.current) {
    console.log("videoRef.current is present");
  }
}, []);

<LiteYouTubeEmbed
  id={post.content.youtubeId}
  title={post.content.title}
  onIframeAdded={() => console.log("onIframeAdded")}
  ref={videoRef}
/>

Expected behavior

I would expect the console to contain logs showing "videoRef.current is present" and "onIframeAdded".

Desktop (please complete the following information):

Additional context

I'm trying to add react-lite-youtube-embed to a Next.js app (v14). We have a number of event handlers we need to attach to the YouTube iframe and I was expecting to do that inside an effect.