-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: useMobile hook * feat: use useLayoutEffect * chore: update comment
- Loading branch information
Showing
4 changed files
with
56 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
lint-staged |
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,18 @@ | ||
import { useLayoutEffect, useState } from 'react'; | ||
import isMobile from '../isMobile'; | ||
|
||
/** | ||
* Hook to detect if the user is on a mobile device | ||
* Notice that this hook will only detect the device type in effect, so it will always be false in server side | ||
*/ | ||
const useMobile = (): boolean => { | ||
const [mobile, setMobile] = useState(false); | ||
|
||
useLayoutEffect(() => { | ||
setMobile(isMobile()); | ||
}, []); | ||
|
||
return mobile; | ||
}; | ||
|
||
export default useMobile; |
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
e59b09c
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.
Successfully deployed to the following URLs:
util – ./
util-git-master-react-component.vercel.app
util.vercel.app
util-react-component.vercel.app