packages
useLocalStorage

useLocalStorage

Sets and gets items from local storage

const [storageItem, setStorageItem] = useLocalStorage(key, initialValue);

Usage

const Component = () => {
  const [storageItem, setStorageItem] = useLocalStorage('useLocalStorage', 'initial');
 
  return (
    <>
      {storageItem}
      <button type='button' onClick={() => setStorageItem('new')}>
        Click Me
      </button>
    </>
  );
};

Arguments


NameTypeRequired?
keystring
initialValueany

Returns


IndexDescriptionType
0Item from localStorageT
1Updater for localStorage(value: T) => void