1.0.8 • Published 2 years ago

@vinsjo/use-local-storage v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 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

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago