Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

screen-wake-lock

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

screen-wake-lock

React library to prevent computer from entering sleep mode

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

screen-wake-lock.js

React library to prevent device from entering sleep mode when app is in active tab.

Installation

# Install using npm
npm install screen-wake-lock
# Install using yarn
yarn add screen-wake-lock

Usage

Prevent device from entering sleep app-wide using WakeLock component

import React from 'react';
import ReactDOM from 'react-dom';
import WakeLock from 'screen-wake-lock';
import App from './App';

ReactDOM.render(
  <React.StrictMode>
    <WakeLock />
    <App />
  </React.StrictMode>,
  document.getElementById('root'),
);

Prevent device from entering sleep mode when a specific component is rendered using WakeLock component

import React from 'react';
import WakeLock from 'screen-wake-lock';

const SpecificComponent = () => {
  return (
    <>
      <WakeLock />
      <div>Sleepless in Seattle</div>
    </>
  );
};

export default SpecificComponent;

Prevent device from entering sleep mode when a specific component is rendered using useWakeLock hook

import React from 'react';
import { useWakeLock } from 'screen-wake-lock';

const SpecificComponent = () => {
  useWakeLock();
  return <div>Sleepless in Seattle</div>;
};

export default SpecificComponent;

Use useWakeLock in debug mode

useWakeLock takes an optional parameter debug. When passed true it will print the status of the wake lock to the console whenever it gets locked or released. for instance when navigating away from the browser tab where the app is running and back. This can be a convenient way to test that the hook is working.

import React from 'react';
import { useWakeLock } from 'screen-wake-lock';

const SpecificComponent = () => {
  useWakeLock(true);
  return <div>Sleepless in Seattle</div>;
};

export default SpecificComponent;

// Screen Wake Lock released: true
// Screen Wake Lock released: false

For contributors

Publishing a new version

Check that linting, formatting, build and tests pass

npm run lint
npm run format
npm run build
npm test

Bump version

npm version [major | minor | patch]

Publish to NPM

npm publish

Keywords

FAQs

Package last updated on 04 Aug 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc