Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
raw
history blame
734 Bytes
import { useCallback, useState } from 'react';
import useLifecycles from './useLifecycles';
import { off, on } from './misc/util';
/**
* read and write url hash, response to url hash change
*/
export const useHash = () => {
const [hash, setHash] = useState(() => window.location.hash);
const onHashChange = useCallback(() => {
setHash(window.location.hash);
}, []);
useLifecycles(
() => {
on(window, 'hashchange', onHashChange);
},
() => {
off(window, 'hashchange', onHashChange);
}
);
const _setHash = useCallback(
(newHash: string) => {
if (newHash !== hash) {
window.location.hash = newHash;
}
},
[hash]
);
return [hash, _setHash] as const;
};