NoSleep.js, in React Hooks form.
Use this hook to take your enabled state and translate it into NoSleep.js enable/disable calls.
Import with either a named or default export:
import { useNoSleep } from "use-no-sleep";
import useNoSleep from "use-no-sleep";useNoSleep takes in a single parameter, enabled, of type boolean.
useNoSleep(enabled);Internally, the NoSleep.js .enable() and .disable() calls are managed by a React useEffect.
The Wake Lock API is not yet standardized or ready for browsers to implement. Until then, NoSleep.js provides a workaround by playing a short silent video in the background.
This repository uses the ViRPo fork of the original richtr/NoSleep.js to help reduce CPU usage. See richtr/NoSleep.js#77.
Thanks so much for contributing! 💖
Here are the steps to set this up locally: You probably want to develop with this locally:
git clone https://github.com/JoshuaKGoldberg/use-no-sleep
cd use-no-sleep
npm i