Skip to content

useFullscreen

Toggle the fullscreen mode on a target element using this hook.

Parameters

  • a ref object of the target element.

Return Values

NameTypeDescription
refRefObjectthe target element reference.
isEnabledBooleanindicates whether the fullscreen mode is enabled on the target element or not.
isErrorUnknownindicates whether is there an error or not.
enterFunctionenter to fullscreen mode, and it can take some fullscreen options.
exitFunctionexit from the fullscreen mode .
toggleFunctiontoggle between enter and exit, and it can take a boolean to force it.

Example Usage

tsx
import { useFullscreen } from 'react-pre-hooks';

export default function Example() {
  const fullscreen = useFullscreen();

  return (
    <main>
      <div onClick={() => fullscreen.toggle()}>
        {fullscreen.isEnabled ? 'Exit' : 'Enter'} fullscreen!
      </div>
    </main>
  );
}
import { useFullscreen } from 'react-pre-hooks';

export default function Example() {
  const fullscreen = useFullscreen();

  return (
    <main>
      <div onClick={() => fullscreen.toggle()}>
        {fullscreen.isEnabled ? 'Exit' : 'Enter'} fullscreen!
      </div>
    </main>
  );
}

Released under the MIT License.