apple2js/js/components/hooks/useHash.ts
Will Scullin ef404735cd
Preact error dialog (#120)
Add error dialog, fix dynamic hash updates.
2022-05-31 17:41:24 -07:00

20 lines
478 B
TypeScript

import { useEffect, useState } from 'preact/hooks';
export const useHash = () => {
const [hash, setHash] = useState(window.location.hash);
const popstateListener = () => {
const hash = window.location.hash;
setHash(hash);
};
useEffect(() => {
window.addEventListener('popstate', popstateListener);
return () => {
window.removeEventListener('popstate', popstateListener);
};
}, []);
return hash;
};