diff --git a/src/hooks/useWideFormat.ts b/src/hooks/useWideFormat.ts index b18a94f48..022d8561d 100644 --- a/src/hooks/useWideFormat.ts +++ b/src/hooks/useWideFormat.ts @@ -1,4 +1,19 @@ +import { useEffect, useState } from 'react'; + +function hasWideFormat() { + return typeof window !== 'undefined' && window.innerWidth > 880; +} + export function useWideFormat() { - const wideFormat = typeof window !== 'undefined' && window.innerWidth > 880; + const [wideFormat, setWideFormat] = useState(hasWideFormat()); + + useEffect(() => { + function handleResize() { + setWideFormat(hasWideFormat()); + } + + window.addEventListener('resize', handleResize); + }, []); + return wideFormat; }