Advanced React Interview QuestionsAdvancedScenario
React · Question 97
A video keeps playing after its Activity becomes hidden. Why can that happen?
Direct answer
Hidden Activity content keeps its DOM rather than destroying it, so intrinsic DOM behavior such as an already-playing video can continue unless your component explicitly stops it during Effect cleanup.
VideoPlayer.jsx
function VideoPlayer({ src }) {
const ref = useRef(null);
useEffect(() => {
const video = ref.current;
return () => {
video?.pause();
};
}, []);
return <video ref={ref} src={src} controls />;
}When Activity becomes hidden, React cleans up Effects, but the DOM node can remain. Some native elements such as video, audio, and iframe can therefore have behavior that is different from true DOM removal.