Build a Weather App in React JS | React JS beginner Tutorial
Video Statistics and Information
Channel: Tyler Potts
Views: 132,440
Rating: 4.9305711 out of 5
Keywords:
Id: GuA0_Z1llYU
Channel Id: undefined
Length: 33min 3sec (1983 seconds)
Published: Sat Jan 11 2020
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.
I'll try this out later, thanks!
I did a weather app like this recently just to pad my portfolio (I'm a beginner myself) and looking through this sub, seems like making a weather app with the OpenWeatherMap API is like the FizzBuzz of React. π€£
Does anyone know where I can find his wallpaper?
Good stuff buddy! Nice tutorial!
Something that bothers me about this code is that the
search
function and theonKeyPress
event handler are re-defined on every render, which happens quite frequently because the input field updates the state ofquery
on every keypress.The
search
function can't be moved into auseCallback
hook, because it depends on the value ofquery
, so the callback hook re-runs on every render as well, to close over the value ofquery
in that render. We can't useuseRef
for the same reason (the ref would refer to a stale value ofsearch
).If this were a class component, the
onKeyPress
andsearch
functions can both be declared as class properties. Thesearch
function can access the value ofsearch
directly withthis.state.query
. Thesearch
function does not need to be redefined on every render, because it does not need to close over the current value ofquery
.How to accomplish the same thing as a stateless functional component using hooks?