From ac514170b336fe3175a000475c842470f17b0e69 Mon Sep 17 00:00:00 2001 From: Jose Enrique Marquez Date: Mon, 20 Sep 2021 07:57:36 -0500 Subject: [PATCH] Fix clear when unmount component --- docs/guides/react.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 (