Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React docs on "Building Your Own Hooks" #2939

Open
iamchangming opened this issue Apr 29, 2020 · 0 comments
Open

React docs on "Building Your Own Hooks" #2939

iamchangming opened this issue Apr 29, 2020 · 0 comments

Comments

@iamchangming
Copy link

@iamchangming iamchangming commented Apr 29, 2020

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."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.