1.0.0 • Published 3 years ago

@hookplus/use-full-screen v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@hookplus/use-fullscreen

React Hook to make any element go Fullscreen

Installation

yarn

yarn add @hookplus/use-fullscreen

npm

npm i @hookplus/use-fullscreen

Usage

import React from "react";
import useFullscreen from "@hookplus/use-fullscreen";

function App() {
  const onChange = (isFull) =>
    console.log(isFull ? "We are in Fullscreen" : "We are not in Fullscreen");
  const { element, triggerFull, exitFull } = useFullscreen(onChange);
  return (
    <div ref={element}>
      <h1>Hello</h1>
      <button onClick={triggerFull}>Make this Fullscreen</button>
      <button onClick={exitFull}>Exit Fullscreen</button>
    </div>
  );
}

Arguments

ArgumentTypeDescriptionArgumentsRequired
onChangefunctionFunction to be called when the screen goes Fullscreen or exits isisFull : Booleanno

Return

useFullscreen returns an object containing the following:

Return valueTypeDescription
elementReact RefRef to add to the element that you want to make fullscreen
triggerFullFunctionFunction to make the element enter fullscreen
exitFullFunctionFunction to make the document exit fullscreen