useWakeLock
Prevents the device screen from dimming or locking using the Screen Wake Lock API.
Loading preview...
The useWakeLock hook requests and releases a 'screen' wake lock via navigator.wakeLock.request('screen'), and automatically re-acquires the lock when the tab returns to 'visible' after being backgrounded.
Installation
Usage
Examples
Declarative Wake Lock Tied to Playback State
Pass a boolean as the first argument to automatically acquire the wake lock when isPlaying is true and release it when false.
Imperative request and release Controls
Omit the boolean argument and use request() and release() directly with error and release callbacks.
API Reference
UseWakeLockOptions
Configuration options for visibility re-acquisition and lifecycle callbacks.
Property
Specification
reacquireOnVisible?uniondefault:true
Automatically re-acquire the screen wake lock when the document becomes visible again
Full Signature
onError?function
Callback fired if requesting the wake lock fails.
Full Signature
Parameters
(errorErrorUseWakeLockReturn
Wake lock status and imperative request / release controls returned by the hook.
Property
Specification
isSupportedunion
Whether the Screen Wake Lock API (
navigator.wakeLock) is supported.Full Signature
isLockedunion
Whether a screen wake lock is currently active.
Full Signature
errorunion
Most recent error thrown while requesting the wake lock, or
null.Full Signature