DEV Community

Discussion on: Run Function after useEffect to Manipulate Data?

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


And see if that works!

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

Thread Thread
mitchelln11 profile image
mitchelln11 Author

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?.weather?.[0].main --- returns cloud/rain/etc.

You know your stuff. It's much appreciated!

Thread Thread
anfo000 profile image

Wow.. I didnt know about the chaining operator.

Thread Thread
taylorbeeston profile image
Taylor Beeston • Edited on

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