diff --git a/docs/guides/react.md b/docs/guides/react.md index 627aa57319..5be9d43d48 100644 --- a/docs/guides/react.md +++ b/docs/guides/react.md @@ -31,17 +31,19 @@ export const VideoJS = ( props ) => { // player.autoplay(options.autoplay); // player.src(options.sources); } - }, [options]); + }, [options, videoRef]); // Dispose the Video.js player when the functional component unmounts React.useEffect(() => { + const player = playerRef.current; + return () => { - if (playerRef.current) { - playerRef.current.dispose(); + if (player) { + player.dispose(); playerRef.current = null; } }; - }, []); + }, [playerRef]); return (