Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed a YouTube iframe using React + Typescript?

Typescript seems to be working against me here. Here's what I want to embed:

<iframe 
    width="560" 
    height="315" 
    src="https://www.youtube.com/embed/BLAH?showinfo=0" 
    frameBorder="0" 
    allow="autoplay; encrypted-media" 
    allowFullScreen></iframe>

The problem is the allow attribute:

TS2339: Property 'allow' does not exist on type 'DetailedHTMLProps<IframeHTMLAttributes<HTMLIFrameElement>, HTMLIFrameElement>'.

...which is true, it's not in index.d.ts. How can I forcibly add this attribute, or somehow cast iframe to any any type, etc?

like image 641
stickfigure Avatar asked Feb 03 '18 00:02

stickfigure


Video Answer


1 Answers

The answer is to change the attribute from allow to data-allow.

like image 101
stickfigure Avatar answered Nov 15 '22 07:11

stickfigure