1import { useRef } from 'react'2import { useFullScreen } from 'react-modern-hooks'34const Demo = () => {5 const ref = useRef(null)6 const { fullScreen, close, open, toggle, error } = useFullScreen(ref)78 if (error) {9 console.log('Error: ', error)10 }1112 return (13 <div>14 <div ref={ref} style={{ background: '#fff' }}>15 <h1> This is the div (one with ref) that will enter fullscreen mode</h1>16 {fullScreen ? (17 <p>Only visible in fullscreen mode</p>18 ) : (19 <p>Not in fullscreen mode</p>20 )}2122 <button onClick={() => open()}>Open FullScreen</button>23 <button onClick={() => close()}>Exit FullScreen</button>2425 <button onClick={() => toggle()}>Toggle Open/Exit FullScreen</button>26 </div>27 </div>28 )29}3031export default Demo
ref - A HTMLElement mutable ref object to toggle to fullscreen
onExit - An optional callback function to run when exiting fullscreen
fullScreen - A boolean value to show if fullscreen or not
open - A function to open the referenced component/element to fullscreen window
close - A function to close/exit the referenced component/element from fullscreen window
toggle - A function to both open and/or close/exit the referenced component/element to and from fullscreen window
error - An error message incase something doesn't go right on opening and/or closing fullscreen window