Father of four under four, three boys and one girl! Full-Stack dev programming mostly in Javascript/TypeScript these days, with a decent amount of Rust on the side
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
Father of four under four, three boys and one girl! Full-Stack dev programming mostly in Javascript/TypeScript these days, with a decent amount of Rust on the side
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
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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 asWeird. 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! TryAnd see if that works!
As for the float formatting, use the good ol' toFixed method like so
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!
Wow.. I didnt know about the chaining operator.
Thanks
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