@remotion/player
Version:
React component for embedding a Remotion preview into your app
21 lines (20 loc) • 665 B
JavaScript
import { useEffect, useRef } from 'react';
const getIsBackgrounded = () => {
if (typeof document === 'undefined') {
return false;
}
return document.visibilityState === 'hidden';
};
export const useIsBackgrounded = () => {
const isBackgrounded = useRef(getIsBackgrounded());
useEffect(() => {
const onVisibilityChange = () => {
isBackgrounded.current = getIsBackgrounded();
};
document.addEventListener('visibilitychange', onVisibilityChange);
return () => {
document.removeEventListener('visibilitychange', onVisibilityChange);
};
}, []);
return isBackgrounded;
};