-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: react-responsive 설치 및 useDevice 훅 추가
- Loading branch information
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useMediaQuery } from 'react-responsive'; | ||
|
||
export function useIsTablet(minWidth = '429px', maxWidth = '768px') { | ||
const [isTablet, setIsTablet] = useState(false); | ||
const tablet = useMediaQuery({ | ||
query: `(min-width: ${minWidth}) and (max-width: ${maxWidth})`, | ||
}); | ||
useEffect(() => { | ||
setIsTablet(tablet); | ||
}, [tablet]); | ||
return isTablet; | ||
} | ||
|
||
export function useIsMobile(maxWidth = '428.999px') { | ||
const [isMobile, setIsMobile] = useState(false); | ||
const mobile = useMediaQuery({ | ||
query: `(max-width:${maxWidth})`, | ||
}); | ||
useEffect(() => { | ||
setIsMobile(mobile); | ||
}, [mobile]); | ||
return isMobile; | ||
} | ||
|
||
export function useDevice() { | ||
const isTablet = useIsTablet(); | ||
const isMobile = useIsMobile(); | ||
|
||
return isTablet ? 'tablet' : isMobile ? 'mobile' : 'desktop'; | ||
} |
This file contains 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