Skip to content

Commit

Permalink
fix: issue with id not being passed through, type definition
Browse files Browse the repository at this point in the history
  • Loading branch information
gojutin committed Mar 12, 2022
1 parent 8fab20b commit c101517
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/react-hook-youtube.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ export function useYoutubePlayer(options: YT.PlayerOptions): {
// COMPONENT
const YoutubePlayer =
React.useMemo((): React.FunctionComponent<YoutubePlayerProps> => {
return (props) => (
<div
className={props.className || ""}
style={props.style}
id={props.id || `youtube-player-${options?.videoId}`}
/>
);
return (props) => {
const playerId = `youtube-player-${props?.id || options?.videoId}`;
return (
<div
className={props.className || ""}
style={props.style}
id={playerId}
/>
);
};
}, [options.videoId]);

/**
Expand Down Expand Up @@ -239,7 +242,8 @@ export function useYoutubePlayer(options: YT.PlayerOptions): {
};

function loadVideo() {
new YT.Player(`youtube-player-${options.videoId}`, {
if (!window?.YT) return;
new window.YT.Player(`youtube-player-${options.videoId}`, {
videoId: options.videoId,
playerVars: options.playerVars,
height: options.height || 390,
Expand Down

0 comments on commit c101517

Please sign in to comment.