v6.0.35

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 '@asuikit/hooks';
import { Button, Text, Code } from '@asuikit/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];