Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to do lazy loading like with the iframe? #234

Closed
brvnonascimento opened this issue Apr 10, 2020 · 1 comment · May be fixed by Summonshr/stocknp.com#45 or PaulaSalinoRibeiro/my-blog#4

Comments

@brvnonascimento
Copy link

No description provided.

@brvnonascimento
Copy link
Author

Here's the solution I came up with:

    const [lazyYoutube, setLazyYoutube] = useState(true)
    const lazyYoutubeHandler = () => setLazyYoutube(prevState => !prevState)
    //bypass safari autoplay blocker, but not Brave so the user will have to click twice with it
    const autoPlayHandler = e => e.target.playVideo()

    return (
                <div className={!lazyYoutube ? `px-0 embed-responsive embed-responsive-16by9` : 'px-0'} >
                    {!lazyYoutube ?
                        <YouTube
                            videoId={video}
                            opts={{autoplay: 1}}
                            onReady={autoPlayHandler}
                            /> :
                        <div className='d-flex h-100 justify-content-center btn p-0' onClick={lazyYoutubeHandler}>
                            <img src='/assets/youtube.svg' alt='Youtube Botão Play' className='yt-button align-self-center' />
                            <img src={`https://img.youtube.com/vi/${video}/sddefault.jpg`} alt={title} className='w-100' />
                        </div>
                    }
      </div>

Foo-x added a commit to Foo-x/react-youtube that referenced this issue Aug 18, 2021

Verified

This commit was signed with the committer’s verified signature. The key has expired.
dtzWill Will Dietz
@Foo-x Foo-x mentioned this issue Aug 18, 2021
ruisaraiva19 pushed a commit that referenced this issue Aug 19, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
* feat: lazy load

Refs #234

* feat: loading to be more specific
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment