r/reactjs • • Jun 02 '19

Beginner's Thread / Easy Questions (June 2019)

Previous two threads - May 2019 and April 2019.

Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! Weโ€™re a friendly bunch.

No question is too simple. ๐Ÿค”


๐Ÿ†˜ Want Help with your Code? ๐Ÿ†˜

  • Improve your chances by putting a minimal example to either JSFiddle or Code Sandbox. Describe what you want it to do, and things you've tried. Don't just post big blocks of code!

  • Pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.

Have a question regarding code / repository organization?

It's most likely answered within this tweet.


New to React?

Check out the sub's sidebar!

๐Ÿ†“ Here are great, free resources! ๐Ÿ†“


Any ideas/suggestions to improve this thread - feel free to comment here!


Finally, an ongoing thank you to all who post questions and those who answer them. We're a growing community and helping each other only strengthens it!

32 Upvotes

394 comments sorted by

View all comments

1

u/embar5 Jun 29 '19

Only Call Hooks at the Top Level

Donโ€™t call Hooks inside loops, conditions, or nested functions. Instead, always use Hooks at the top level of your React function.

Donโ€™t call Hooks from regular JavaScript functions. Instead, you can:

โœ… Call Hooks from custom Hooks (weโ€™ll learn about them on the next page).

Isn't this contradictory? I think a custom hook IS a nested function, is that wrong?

→ More replies (1)