Created
March 20, 2024 05:38
-
-
Save rjcnd105/295b44f78b607f4a597a24555632acdf to your computer and use it in GitHub Desktop.
react-use사용
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { DESKTOP_WIDTH } from '@remember_web/ui'; | |
| import { useMedia, useUpdateEffect } from 'react-use'; | |
| type UseMobileSizeProps = { | |
| isDefaultMobile?: boolean; | |
| onMediaChange?: (isMobile: boolean) => void; | |
| }; | |
| export const useMobileSize = ({ | |
| isDefaultMobile = false, | |
| onMediaChange, | |
| }: UseMobileSizeProps = {}) => { | |
| const isMobile = useMedia( | |
| `(max-width: ${DESKTOP_WIDTH}px)` as string, | |
| isDefaultMobile | |
| ); | |
| useUpdateEffect(() => { | |
| if (onMediaChange) { | |
| onMediaChange(isMobile); | |
| } | |
| }, [isMobile]); | |
| return isMobile; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment