useWakeLock
Hook that provides a wake lock functionality
browser
low
test coverage
Last changed: 7 months ago
TIP
This hook uses navigator.wakeLock browser api to provide enhanced functionality. Make sure to check for compatibility with different browsers when using this api
Installation
Library
CLI
Manual
typescript
import { useWakeLock } from '@siberiacancode/reactuse';Usage
typescript
const { supported, active, request, release } = useWakeLock();Demo
Api
Parameters
| Name | Type | Default | Note |
|---|---|---|---|
| options? | immediately | - | Configuration options for the hook. |
Returns
UseWakeLockReturn
Type declaration
typescript
export interface UseWakeLockOptions {
/** Determines if the wake lock should be automatically reacquired when the document becomes visible. */
immediately?: boolean;
/** A string specifying the screen wake lock type. */
type?: WakeLockType;
}
export interface UseWakeLockReturn {
/** Indicates if the wake lock is currently active. */
active: boolean;
/** Indicates if the Wake Lock API is supported in the current environment. */
supported: boolean;
/** Function to release the wake lock. */
release: () => Promise<void>;
/** Function to request the wake lock. */
request: () => Promise<void>;
}Source
Source • DemoContributors
D
A