1
0
mirror of https://github.com/videojs/video.js.git synced 2024-11-28 08:58:46 +02:00

docs(react): fix clear when unmount component (#7433)

Improve documentation on functional components to clean up reference if the component is unmounted.

Fixes #7361
This commit is contained in:
Jose Enrique Marquez 2021-11-10 14:03:39 -05:00 committed by GitHub
parent b97be4d5cd
commit fdb87d8b72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 (
<div data-vjs-player>