be2c60d3f3
* Memoize calculating sale amount on your bets list * Don't re-render more than necessary with `useIsMobile` hook * Use `useIsMobile` hook in `AmountInput`
14 lines
455 B
TypeScript
14 lines
455 B
TypeScript
import { useEffect, useState } from 'react'
|
|
|
|
export function useIsMobile(threshold?: number) {
|
|
const [isMobile, setIsMobile] = useState<boolean>()
|
|
useEffect(() => {
|
|
// 640 matches tailwind sm breakpoint
|
|
const onResize = () => setIsMobile(window.innerWidth < (threshold ?? 640))
|
|
onResize()
|
|
window.addEventListener('resize', onResize)
|
|
return () => window.removeEventListener('resize', onResize)
|
|
}, [threshold])
|
|
return isMobile
|
|
}
|