New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-use-wake-lock

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-wake-lock

React hooks to make it easier to use Screen Wake Lock API

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
368
-14.02%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

react

FAQs

Package last updated on 25 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts