use-hash

Get and set hash value in url
Import

Usage

use-hash lets you get hash from url, subscribe to its changes with hashchange event and set it:

Current hash:
import { useHash, randomId } from '@mantine/hooks';
import { Button, Text, Code } from '@mantine/core';
function Demo() {
const [hash, setHash] = useHash();
return (
<>
<Button onClick={() => setHash(randomId())}>Set hash to random string</Button>
<Text>Current hash: <Code>{hash}</Code></Text>
</>
);
}

Definition

function useHash(): readonly [string, (value: string) => void];