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."
The text was updated successfully, but these errors were encountered:
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:
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."
The text was updated successfully, but these errors were encountered: