Hi Nathan, great tutorial, thanks a lot for sharing it!
I'm learning react and after reading your tutorial have a few doubts.
Wouldn't be this against what react advice related to the use of hooks? Copy paste from the official docs.
Sorry I hope you can throw some light! Thanks again!
I am a little bit late for the party but if do not figure it out by now. I will shed some light since the author did not.
When they are saying to call the hooks inside loops, nested functions or conditions does not mean that they are not there for being used in map functions. They are more concerned with the fact of the order of hooks and especially with cases where there is no guarantee that you can preserve the state therefore maintaining the order.
One case is with if statements:
if(!userState) const [user,setUser] = useState('guest'); // order here can not be preserved because it rely upon the userState variable
if(!userState) const [user,setUser] = useState('guest');
I do not have a good example about nested functions or for examples but again the order has to be preserved.
Oh pretty cool! This has been wandering my thoughts some time, finally some light indeed! thanks!
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.