-
Notifications
You must be signed in to change notification settings - Fork 2
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
First draft useScreenOrientation #325
base: main
Are you sure you want to change the base?
First draft useScreenOrientation #325
Conversation
defaultValue = false, | ||
): boolean { | ||
defaultValue?: boolean, | ||
): boolean | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in what scenario would you want undefined
to be returned ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be helpful for SSR, and only on client side return a boolean 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I wonder what you would do with this then... not render something at all?
You always get a hydration error then? And this value on the client should only be used after the first render?
isLandscape: boolean | undefined; | ||
isPortrait: boolean | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are mutually exclusive, so why not return 'landscape' | 'portrait'
?
I don't know if it's helpful to add this as a hook because the only thing it does is provide a default value for the That'll mean that you can get the same behaviour with something like this: import { useMediaQuery, landscapeOrientationMediaQuery } from '@mediamonks/react-kit`
const isLandscape = useMediaQuery(landscapeOrientationMediaQuery) instead of import { useScreenOrientation } from '@mediamonks/react-kit`
const isLandscape = useScreenOrientation() Additionally, browsers have a not super well supported |
Copilot
AI
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 4 out of 6 changed files in this pull request and generated 1 suggestion.
Files not reviewed (2)
- src/hooks/useMediaQuery/useMediaQuery.mdx: Language not supported
- src/hooks/useScreenOrientation/useScreenOrientation.mdx: Language not supported
Comments skipped due to low confidence (2)
src/hooks/useScreenOrientation/useScreenOrientation.ts:17
- Add a test case to cover the scenario where
isLandscape
isundefined
to ensure the behavior is as expected.
isPortrait: !isLandscape,
src/hooks/useMediaQuery/useMediaQuery.ts:57
- The return type of
useMediaQuery
has been changed toboolean | undefined
. This might introduce unintended behavior if the calling code does not handleundefined
values. Ensure that all usages ofuseMediaQuery
are updated to handleundefined
values appropriately.
): boolean | undefined {
Co-authored-by: Copilot <[email protected]>
No description provided.