Skip to content

Commit

Permalink
docs(react): fix clear when unmount component (#7433)
Browse files Browse the repository at this point in the history
Improve documentation on functional components to clean up reference if the component is unmounted.

Fixes #7361
  • Loading branch information
jomarquez21 authored Nov 10, 2021
1 parent b97be4d commit fdb87d8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/guides/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit fdb87d8

Please sign in to comment.