in theme/src/components/nav-drawer.js [13:40]
export function useNavDrawerState(breakpoint) {
// Handle string values from themes with units at the end
if (typeof breakpoint === 'string') {
breakpoint = parseInt(breakpoint, 10)
}
const [isOpen, setOpen] = React.useState(false)
const onResize = React.useCallback(() => {
if (window.innerWidth >= breakpoint) {
setOpen(false)
}
}, [setOpen])
const debouncedOnResize = React.useCallback(debounce(onResize, 250), [onResize])
React.useEffect(() => {
if (isOpen) {
window.addEventListener('resize', debouncedOnResize)
return () => {
// cancel any debounced invocation of the resize handler
debouncedOnResize.cancel()
window.removeEventListener('resize', debouncedOnResize)
}
}
}, [isOpen, debouncedOnResize])
return [isOpen, setOpen]
}