use-no-sleep

NoSleep.js, in React Hooks form.

Usage no npm install needed!

<script type="module">
  import useNoSleep from 'https://cdn.skypack.dev/use-no-sleep';
</script>

README

use-no-sleep

Code Style: Prettier TypeScript: Strict Circle CI

NoSleep.js, in React Hooks form. Use this hook to take your enabled state and translate it into NoSleep.js enable/disable calls.

Usage

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.

FAQs

Why NoSleep.js?

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.

Which NoSleep.js Version Does This Use?

This repository uses the ViRPo fork of the original richtr/NoSleep.js to help reduce CPU usage. See richtr/NoSleep.js#77.

Development

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