DEV Community

Discussion on: Run Function after useEffect to Manipulate Data?

 
mitchelln11 profile image
mitchelln11

Sweet, getting 57.938000000000045, so I just need to get that, but that did the trick. Thank you so much.

As far as the object goes with REACT, it's weird, should be openWeather.main.temp, but that comes back undefined. Instead, you have to add it as

openWeather.main && openWeather.main.temp
Thread Thread
 
taylorbeeston profile image
Taylor Beeston

Weird. That's likely because openWeather is an empty object until the API call finishes. You might be able to use the new optional chaining operator to get past that! Try

openWeather?.main?.temp

And see if that works!

As for the float formatting, use the good ol' toFixed method like so

kToF(kelvin).toFixed(2)
Thread Thread
 
mitchelln11 profile image
mitchelln11

57.15, perfect.
I also had no idea about the optional chaining thing. Good to know thanks. That part looks like it's working as well.

openWeather?.main?.temp
AND
openWeather?.weather?.[0].main --- returns cloud/rain/etc.

You know your stuff. It's much appreciated!

Thread Thread
 
anfo000 profile image
anfo000

Wow.. I didnt know about the chaining operator.
Thanks

Thread Thread
 
taylorbeeston profile image
Taylor Beeston • Edited

No problem guys! Happy to help.

About optional chaining, it's extremely new, as in I think it just became official standardized this year, so please make sure you're running any code that uses it through babel (if you used create-react-app it should be doing this already) because browser support is going to be terrible