DEV Community

Discussion on: Simplest way to embed a Youtube video in your React app

Collapse
 
prmichaelsen profile image
Patrick Michaelsen • Edited

one change I needed: export const YoutubeEmbed = (embedId) =>
embedId && ( <iframe ... />);

jk that didn't fix my problem. for some reason it only works when I hard code the embedId

It's trying to fetch embed/[Object object]

For completenes sake, turns out it's a problem with my code that generates the embedId. I wish you could edit comments so I didn't have to triple post, but alas.

Collapse
 
eyassh profile image
Eyas

@prmichaelsen That's because you have a typo, instead of:

export const YoutubeEmbed = (embedId) =>

try:

export const YoutubeEmbed = ({embedId}) =>

The [Object object] in your string is the first argument. You call it embedId here, but the first argument to a React FunctionComponent is the props object. For this case, it will look something like this:

{
  embedId: "myidstring",
  children: null
}
Enter fullscreen mode Exit fullscreen mode

or similar.