Skip to content

Commit fdb87d8

Browse files
authored
docs(react): fix clear when unmount component (#7433)
Improve documentation on functional components to clean up reference if the component is unmounted. Fixes #7361
1 parent b97be4d commit fdb87d8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

docs/guides/react.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,19 @@ export const VideoJS = ( props ) => {
3131
// player.autoplay(options.autoplay);
3232
// player.src(options.sources);
3333
}
34-
}, [options]);
34+
}, [options, videoRef]);
3535

3636
// Dispose the Video.js player when the functional component unmounts
3737
React.useEffect(() => {
38+
const player = playerRef.current;
39+
3840
return () => {
39-
if (playerRef.current) {
40-
playerRef.current.dispose();
41+
if (player) {
42+
player.dispose();
4143
playerRef.current = null;
4244
}
4345
};
44-
}, []);
46+
}, [playerRef]);
4547

4648
return (
4749
<div data-vjs-player>

0 commit comments

Comments
 (0)