Skip to content

Commit

Permalink
feat: 🎸 support useBattery hook on server side
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Aug 20, 2019
1 parent 0e9894d commit 5d31cf0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/useBattery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type UseBatteryState =
| { isSupported: true; fetched: false } // battery API supported but not fetched yet
| BatteryState & { isSupported: true; fetched: true }; // battery API supported and fetched

const nav: NavigatorWithPossibleBattery = navigator;
const isBatteryApiSupported = nav && typeof nav.getBattery !== 'undefined';
const isBatteryApiSupported =
typeof navigator === 'object' && typeof (navigator as NavigatorWithPossibleBattery).getBattery === 'function';

function useBatteryMock(): UseBatteryState {
return { isSupported: false };
Expand Down Expand Up @@ -85,7 +85,7 @@ function useBattery(): UseBatteryState {
React.useEffect(() => {
isMounted.current = true;

nav.getBattery!().then((bat: BatteryManager) => {
(navigator as NavigatorWithPossibleBattery).getBattery!().then((bat: BatteryManager) => {
battery.current = bat;

bindBatteryEvents();
Expand Down

0 comments on commit 5d31cf0

Please sign in to comment.