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
U talking about just moving the inline function to the LocalWeather component, then just running it like your last block of code?
I just tried that, and I'm getting the following error: Line 11:8: React Hook useEffect has a missing dependency: 'axiosGet'. Either include it or remove the dependency array react-hooks/exhaustive-deps
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
I am so sorry, I just realized what you are trying to accomplish. I misunderstood your problem.
As was said before me, you need your KelvinConvert component to return valid JSX in order to be rendered. This can be done by changing its definition to be something like this:
And then passing your Kelvin temperature to it by changing
<KelvinConvert/>// Trying to add converted temperature here
To
<KelvinConvertkelvin={openWeather.kelvin}/>
When the useEffect hook finishes, it will update the prop sent to your component.
Please note, I don't actually know what the openWeather object will look like since I haven't used that API, nor do I know specifically what you're trying to get from it, so it is very likely that using openWeather.kelvin like I wrote above will not work. Please replace that with the data you want your KelvinConvert component to convert.
Also, I wrote all of this on my phone, so please forgive any typos or bad code
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.
Hi Mitchell, is there any reason why you can't inline
into your
LocalWeather
component and then simply changeaxiosGet
toU talking about just moving the inline function to the LocalWeather component, then just running it like your last block of code?
I just tried that, and I'm getting the following error:
Line 11:8: React Hook useEffect has a missing dependency: 'axiosGet'. Either include it or remove the dependency array react-hooks/exhaustive-deps
I am so sorry, I just realized what you are trying to accomplish. I misunderstood your problem.
As was said before me, you need your KelvinConvert component to return valid JSX in order to be rendered. This can be done by changing its definition to be something like this:
And then passing your Kelvin temperature to it by changing
To
When the useEffect hook finishes, it will update the prop sent to your component.
Please note, I don't actually know what the openWeather object will look like since I haven't used that API, nor do I know specifically what you're trying to get from it, so it is very likely that using
openWeather.kelvin
like I wrote above will not work. Please replace that with the data you want yourKelvinConvert
component to convert.Also, I wrote all of this on my phone, so please forgive any typos or bad code
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