File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ type UseBatteryState =
25
25
| { isSupported : true ; fetched : false } // battery API supported but not fetched yet
26
26
| BatteryState & { isSupported : true ; fetched : true } ; // battery API supported and fetched
27
27
28
- const nav : NavigatorWithPossibleBattery = navigator ;
29
- const isBatteryApiSupported = nav && typeof nav . getBattery !== 'undefined ';
28
+ const isBatteryApiSupported =
29
+ typeof navigator === 'object' && typeof ( navigator as NavigatorWithPossibleBattery ) . getBattery === 'function ';
30
30
31
31
function useBatteryMock ( ) : UseBatteryState {
32
32
return { isSupported : false } ;
@@ -85,7 +85,7 @@ function useBattery(): UseBatteryState {
85
85
React . useEffect ( ( ) => {
86
86
isMounted . current = true ;
87
87
88
- nav . getBattery ! ( ) . then ( ( bat : BatteryManager ) => {
88
+ ( navigator as NavigatorWithPossibleBattery ) . getBattery ! ( ) . then ( ( bat : BatteryManager ) => {
89
89
battery . current = bat ;
90
90
91
91
bindBatteryEvents ( ) ;
You can’t perform that action at this time.
0 commit comments