Bootstrap app

This commit is contained in:
He4eT 2021-02-19 00:53:39 +05:00
commit 5f5d23f4de
3 changed files with 66 additions and 2 deletions

View file

@ -0,0 +1,21 @@
import {
useState, useEffect, useCallback
} from 'preact/hooks'
export const useHashLocation = () => {
const currentLoc = () =>
window.location.hash.replace('#', '') || '/'
const [loc, setLoc] = useState(currentLoc())
useEffect(() => {
const handler = () => setLoc(currentLoc())
window.addEventListener('hashchange', handler)
return () => window.removeEventListener('hashchange', handler)
}, [])
const navigate = useCallback(to =>
(window.location.hash = to.replace('#/', '')), [])
return [loc, navigate]
}