mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
ef404735cd
Add error dialog, fix dynamic hash updates.
20 lines
478 B
TypeScript
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;
|
|
};
|