React docs on "Building Your Own Hooks"
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 11.8k
- Fork
- 7.9k
- Merge medio
- 1g 11h
- PR unite (30g)
- 11
Descrizione
Please provide guidance if returning elements (or ()=>elements) from custom hook is a good practice or not.
We have a PageLayout component like the following in our own app:
<PageLayout
topBarButtons={..}
onRender={..}
/>
We want to encapsulate topBarButtons and onRender logic within a custom hook, so that the hook is reusable and shippable without PageLayout. (topBarButtons and onRender will share some state, and useOurHook returns [topBarButtons, onRenderFunc]).
This works fine, if not perfect, for me. But since there are so few custom hook example that returns UI elements (or function that returns UI elements like onRender), the team have doubt about this pattern.
I know the doc has the following statement, but I think this is a very common scenario that deserves a sentence or two in the React docs.
"useYourImagination()
Custom Hooks offer the flexibility of sharing logic that wasn’t possible in React components before. You can write custom Hooks that cover a wide range of use cases like form handling, animation, declarative subscriptions, timers, and probably many more we haven’t considered."
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 pagina della documentazione "Building Your Own Hooks" e rivedi le indicazioni e gli esempi esistenti sugli Hooks personalizzati. Aggiungi una spiegazione concisa sull’appropriatezza del pattern che restituisce elementi o funzioni che restituiscono elementi, incluso lo scenario di stato condiviso descritto qui; la pagina dovrebbe rispondere alla domanda del team senza richiedere il contesto specifico dell’applicazione di questo issue.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, react
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 50/100