3.0.2 โ€ข Published 8 months ago

react-screen-wake-lock v3.0.2

Weekly downloads
13
License
MIT
Repository
github
Last release
8 months ago

Features

  • ๐ŸŒ Follows the W3C Screen Wake Lock API specifications
  • ๐Ÿช Easy to use - Just one react hook useWakeLock
  • ๐Ÿชถ Lightweight & 0 Dependency - Less than 650b
  • ๐Ÿ”Œ Easily integration - It works without additional configuration (React, remix, Next.js...)
  • ๐Ÿงช Ready to test - Mocks the Screen Wake Lock with Jest
  • โš ๏ธ Browser Support - Screen Wake Lock API

Examples (Demo)

Installation

yarn add react-screen-wake-lock

or

npm i react-screen-wake-lock

Usage

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

function Component() {
  const { isSupported, released, request, release } = useWakeLock({
    onRequest: () => alert('Screen Wake Lock: requested!'),
    onError: () => alert('An error happened ๐Ÿ’ฅ'),
    onRelease: () => alert('Screen Wake Lock: released!'),
  });

  return (
    <div>
      <p>
        Screen Wake Lock API supported: <b>{`${isSupported}`}</b>
        <br />
        Released: <b>{`${released}`}</b>
      </p>
      <button
        type="button"
        onClick={() => (released === false ? release() : request())}
      >
        {released === false ? 'Release' : 'Request'}
      </button>
    </div>
  );
}

export default Component;

Props

Propdescriptiondefaultrequired
onRequestcalled on successfully navigator.wakeLock.requestundefinedfalse
onErrorcalled when caught an error from navigator.wakeLock.requestundefinedfalse
onReleasecalled when wake lock is releasedundefinedfalse

Returns

Propdescriptiontype
isSupportedBrowser support for the Screen Wake Lock APIboolean
releasedOnce WakeLock is released, released become true and the value never changes againbooleanundefined
requestReturns a promise which allows control over screen dimming and lockingfunction
releaseReturns a promise that is resolved once the sentinel has been successfully releasedfunction

Testing

To write tests with ease, follow this guide

Author

๐ŸŒˆ Joris ยท @_jorisre

3.0.2

8 months ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.10

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago