1.0.8 • Published 3 years ago

@vinsjo/use-local-storage v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@vinsjo/use-local-storage

@vinsjo/use-local-storage a react hook for storing a state in localStorage

Package is bundled using microbundle

Installation

npm i @vinsjo/use-local-storage

Usage

import useLocalStorage from '@vinsjo/use-local-storage';

const App = () => {
    const [storedState, setStoredState] = useLocalStorage(
        // storageKey:
        // key to item in localStorage
        'my-storage-key',
        // initialState:
        // optional parameter with initial state or function returning initial state.
        // only stored in localStorage if nothing is already stored with the provided
        // key OR overwrite is set to true.
        // default value is null
        { foo: 'bar' },
        // overwrite:
        // optional parameter indicates if initialState should overwrite already
        // stored value.
        // default value is false
        false
    );

    return <>{storedState.foo}</>;
};
1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago