Piplup
@piplup/utilsHooks

useLocalStorage

Reactive localStorage hook that synchronizes a key with state.

import { useLocalStorage } from "@piplup/utils";

function Component() {
  const [value, setValue] = useLocalStorage('my-key', 'default');

  return (
    <div>
      <div>Value: {value}</div>
      <button onClick={() => setValue('updated')}>Set</button>
    </div>
  );
}

Props

Prop

Type

Return value

Prop

Type

On this page