Explanation on what can go wrong if Hooks were called inside loops or nested functions?
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 11.8k
- Fork
- 7.9k
- Merge medio
- 1g 11h
- PR unite (30g)
- 11
Descrizione
The Rules of Hooks section states that the first rule of Hooks is to only call hooks at the top level, i.e. "Don’t call Hooks inside loops, conditions, or nested functions". Later in the section, it explains what happens if we put a Hook call inside a condition. This still leaves me with some questions/doubts though. Are there examples where something can go wrong if Hooks were:
- called inside a loop?
- called inside a nested function? Furthermore, isn't a custom hook just a nested function? 🤔
I've tried to dig into some related questions on Stack Overflow here and here, but the answers provided only give the correct examples, but not the incorrect ones.
Could you provide incorrect examples for the other two cases? Or at least a little bit clarification would be most appreciated. :)
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dalla sezione Rules of Hooks, soprattutto dalla spiegazione esistente delle chiamate condizionali degli Hooks. Aggiungi esempi errati o chiarimenti che riguardino gli Hooks nei cicli e nelle funzioni annidate, incluso come differiscono i custom Hooks, e considera il lavoro completato quando questi casi saranno spiegati chiaramente nella documentazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, react
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100