This commit is contained in:
Timothy Z. 2026-05-01 18:37:19 +03:00
parent 5686019587
commit 42579ce297
2 changed files with 13 additions and 10 deletions

View file

@ -3,17 +3,13 @@
import { createContext } from 'react';
export type FullscreenContextValue = readonly [
boolean,
() => Promise<void> | void,
() => void,
() => void,
fullscreen: boolean,
requestFullscreen: () => Promise<void> | void,
exitFullscreen: () => void,
toggleFullscreen: () => void,
];
const noop = () => undefined;
const defaultValue: FullscreenContextValue = [false, noop, noop, noop];
const FullscreenContext = createContext<FullscreenContextValue>(defaultValue);
const FullscreenContext = createContext<FullscreenContextValue | null>(null);
FullscreenContext.displayName = 'FullscreenContext';

View file

@ -3,6 +3,13 @@
import { useContext } from 'react';
import FullscreenContext from './FullscreenContext';
const useFullscreen = () => useContext(FullscreenContext);
const useFullscreen = () => {
const value = useContext(FullscreenContext);
if (value === null) {
throw new Error('useFullscreen must be used inside FullscreenProvider');
}
return value;
};
export default useFullscreen;