Skip to content

Commit

Permalink
Add isLandscapeScreen hook (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy Brauner authored Aug 30, 2023
1 parent d5b13cc commit 0360921
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/front/src/components/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Link, Stack, TManageTransitions } from "@cher-ami/router"

import debug from "@wbe/debug"
import { EPages } from "~/routes"
const log = debug(`front:*`)
const log = debug(`front:App`)

export interface IProps {}

Expand Down
25 changes: 25 additions & 0 deletions apps/front/src/libs/hooks/useIsLandscapeScreen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useEffect, useState } from "react"

/**
* useIsLandscapeScreen
* @return boolean
*/
export function useIsLandscapeScreen(): boolean {
const [isLandscapeScreen, setIsLandscapeScreen] = useState<boolean>(
window.innerWidth > window.innerHeight
)

const handler = () => {
setIsLandscapeScreen(window.innerWidth > window.innerHeight)
}

useEffect(() => {
handler()
window.addEventListener("resize", handler)
return () => {
window.removeEventListener("resize", handler)
}
}, [])

return isLandscapeScreen
}

0 comments on commit 0360921

Please sign in to comment.