|
Download react-use/docs/useSessionStorage.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 799 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useSessionStorage.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/useSessionStorage.md
-
curl -L -o useSessionStorage.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useSessionStorage.md
799 Bytes
useSessionStorage
React side-effect hook that manages a single sessionStorage key.
Usage
import {useSessionStorage} from 'react-use';
const Demo = () => {
const [value, setValue] = useSessionStorage('my-key', 'foo');
return (
<div>
<div>Value: {value}</div>
<button onClick={() => setValue('bar')}>bar</button>
<button onClick={() => setValue('baz')}>baz</button>
</div>
);
};
Reference
useSessionStorage(key);
useSessionStorage(key, initialValue);
useSessionStorage(key, initialValue, raw);
key—sessionStoragekey to manage.initialValue— initial value to set, if value insessionStorageis empty.raw— boolean, if set totrue, hook will not attempt to JSON serialize stored values.