1.0.1 • Published 2 months ago

react-use-wake-lock v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

npm Build Status Coverage Status gzip size

React Use Wake Lock

Easily integrate Screen Wake Lock API in your app

  • Zero-dependencies
  • Tiny size (less than 1Kb)
  • Typescript support
  • Auto reacquiring a wake lock out of the box
  • 100% test coverage

Demo

Installation

npm install react-use-wake-lock --save

or

yarn add react-use-wake-lock

Minimal example

import useWakeLock from "react-use-wake-lock";

function MinimalExampleComponent() {
  const { isSupported, isLocked, request, release } = useWakeLock();

  return (
    <div>
      <h3>Screen Wake Lock API supported: {isSupported ? "Yes" : "No"}</h3>
      <h3>Locked: {`${isLocked ? "Yes" : "No"}`}</h3>
      <button type="button" onClick={() => (isLocked ? release() : request())}>
        {isLocked ? "Release" : "Request"}
      </button>
    </div>
  );
}

useWakeLock API

Params

  • onError(error: Error, errorType: "request" | "release") - callback called in case of any error during acuqiring lock or releasing it
  • onLock(lock: WakeLockSentinel) - callback for successful acquiring of a lock
  • onRelease(lock: WakeLockSentinel) - callback called on releasing the lock

Returns

  • isSupported: boolean - is Screen Wake Lock API supported by a browser
  • isLocked: boolean - current state of a lock
  • request: () => void - request a lock
  • release: () => void - release the lock
1.0.1

2 months ago

1.0.0

2 months ago

0.0.18

6 months ago

0.0.17

9 months ago

0.0.16

9 months ago

0.0.15

9 months ago

0.0.14

9 months ago

0.0.12

9 months ago

0.0.10

9 months ago

0.0.9

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago