You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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 amatchMedia
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?
The text was updated successfully, but these errors were encountered: