Shadcn Hooks

useBattery

A hook to monitor battery information

Loading...

Installation

npx shadcn@latest add @shadcnhooks/use-battery

API

export interface UseBatteryState {
  isSupported: boolean
  charging: boolean
  chargingTime: number
  dischargingTime: number
  level: number
}

/**
 * Monitor the current battery information using the Battery Status API.
 *
 * @returns Current battery state and support flag.
 */
export function useBattery(): UseBatteryState

Credits

Last updated on

On this page