-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-essentials): add useUserAgent hook
- Loading branch information
1 parent
6e87a68
commit 78a85e3
Showing
4 changed files
with
30 additions
and
3 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,5 @@ | ||
--- | ||
"@codedazur/react-essentials": minor | ||
--- | ||
|
||
The useUserAgent hook has been added. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,20 @@ | ||
import Bowser from "bowser"; | ||
import { useEffect, useState } from "react"; | ||
|
||
type Result = Bowser.Parser.ParsedResult; | ||
|
||
let globalResult: Result; | ||
|
||
export function useUserAgent(): Result | undefined { | ||
const [result, setResult] = useState<Result>(); | ||
|
||
useEffect(() => { | ||
if (!globalResult) { | ||
globalResult = Bowser.parse(window.navigator.userAgent); | ||
} | ||
|
||
setResult(globalResult); | ||
}, []); | ||
|
||
return result; | ||
} |
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