import { useBattery } from './useBattery' import { useBeforeUnload } from './useBeforeUnload' export function App() { const { supported, loading, level, charging, chargingTime, dischargingTime, error } = useBattery() // Ask for confirmation when leaving the page (custom message may be ignored by some browsers) useBeforeUnload(true, 'Are you sure you want to leave this page? Unsaved battery info will be lost.') if (!supported) { return (
Battery Status API is not supported by this browser.
Tip: On some desktop browsers, this API may be disabled for privacy reasons.
Loading…
) : error ? ({error}
) : (