Skip to content

Latest commit

Β 

History

History
37 lines (27 loc) Β· 863 Bytes

useSessionStorage.md

File metadata and controls

37 lines (27 loc) Β· 863 Bytes

useSessionStorage

Vue side-effect hook that manages a single sessionStorage key.

Usage

import {useSessionStorage} from 'vue-next-use';

const Demo = {
  setup(){
      const [value, setValue] = useSessionStorage('my-key', 'foo');

      return (
          <div>
              <div>Value: {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 β€” sessionStorage key to manage.
  • initialValue β€” initial value to set, if value in sessionStorage is empty.
  • raw β€” boolean, if set to true, hook will not attempt to JSON serialize stored values.