Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const [isAvailable, batteryLevel, batteryState, lowPowerMode] = await Promise.all([
Battery.isAvailableAsync(),
Battery.getBatteryLevelAsync(),
Battery.getBatteryStateAsync(),
Battery.isLowPowerModeEnabledAsync(),
]);
setIsAvailable(isAvailable && false);
setBatteryLevel(batteryLevel);
setBatteryState(batteryState);
setLowPowerMode(lowPowerMode);
})();
const batteryLevelListener = Battery.addBatteryLevelListener(({ batteryLevel }) =>
setBatteryLevel(batteryLevel)
);
const batteryStateListener = Battery.addBatteryStateListener(({ batteryState }) =>
setBatteryState(batteryState)
);
const lowPowerModeListener = Battery.addLowPowerModeListener(({ lowPowerMode }) =>
setLowPowerMode(lowPowerMode)
);
return () => {
batteryLevelListener && batteryLevelListener.remove();
batteryStateListener && batteryStateListener.remove();
lowPowerModeListener && lowPowerModeListener.remove();
};
}, []);