|
Download react-use/docs/useHash.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 840 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useHash.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/useHash.md
-
curl -L -o useHash.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useHash.md
840 Bytes
useHash
React sensor hook that tracks browser's location hash.
Usage
import {useHash} from 'react-use';
const Demo = () => {
const [hash, setHash] = useHash();
useMount(() => {
setHash('#/path/to/page?userId=123');
});
return (
<div>
<div>window.location.href:</div>
<div>
<pre>{window.location.href}</pre>
</div>
<div>Edit hash: </div>
<div>
<input style={{ width: '100%' }} value={hash} onChange={e => setHash(e.target.value)} />
</div>
</div>
);
};
API
const [hash, setHash] = useHash()
Get latest url hash with hash and set url hash with setHash.
hash: string: get current url hash. listen tohashchangeevent.setHash: (newHash: string) => void: change url hash. Invoke this method will triggerhashchangeevent.