manifold/web/hooks/use-is-mobile.ts
Marshall Polaris be2c60d3f3
Fix some rendering issues on contract page (#933)
* Memoize calculating sale amount on your bets list

* Don't re-render more than necessary with `useIsMobile` hook

* Use `useIsMobile` hook in `AmountInput`
2022-09-25 16:43:53 -07:00

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
}