Skip to content

Instantly share code, notes, and snippets.

@rjcnd105
Created March 20, 2024 05:38
Show Gist options
  • Select an option

  • Save rjcnd105/295b44f78b607f4a597a24555632acdf to your computer and use it in GitHub Desktop.

Select an option

Save rjcnd105/295b44f78b607f4a597a24555632acdf to your computer and use it in GitHub Desktop.
react-use사용
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