How to convert this in functional component ?
I have done something like this ...
constgetLevel=async()=>{console.log("A: "+(awaitBattery.getBatteryLevelAsync()));letbatteryLevel=Math.round((awaitBattery.getBatteryLevelAsync())*100);setLevel(batteryLevel);Battery.addBatteryLevelListener(({batteryLevel})=>{batteryLevel=Math.round(batteryLevel*100);setLevel(batteryLevel);console.log("B: "+batteryLevel);});};useEffect(()=>{// Anything in here is fired on component mount.// componentDidMountgetLevel();// componentWillUnmountreturn()=>{// Anything in here is fired on component unmount.};},[]);
Hi, I need a help
How to convert this in functional component ?
I have done something like this ...
I am facing problem in
return function
If you don't need anything to fire on component unmount, you can remove the return.