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

Support passing null/false or a function to do nothing #31

Open
exogen opened this issue May 8, 2019 · 0 comments
Open

Support passing null/false or a function to do nothing #31

exogen opened this issue May 8, 2019 · 0 comments

Comments

@exogen
Copy link

exogen commented May 8, 2019

Since React has a requirement that hooks be called unconditionally, I find that it sometimes causes hooks to need to support somewhat less elegant APIs than what would be ideal. This is one of those cases:

Since you can't call hooks conditionally, it's helpful to add support for passing a special value to the hook like false, or possibly via a function like () => someCondition ? breakpoint : false to make it do nothing until our condition is met. So in use-media's case it would not set up a matchMedia observer.

AFAIK this is the only way to work around the no-conditional requirement besides moving the hook usage into its own component and conditionally rendering that (not always possible depending on what you're doing).

Any thoughts about supporting that?

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

No branches or pull requests

1 participant