@sil/storage
v0.0.7
Published
Keep state in storage
Downloads
79
Readme
Storage
Save your state in localstorage and automatically retrieve on initialisation.
Installation
npm install @sil/storage
Usage
Example in Vue, initialize a state and make sure the state taken from local storage when available. The watchState
makes sure your state will automatically be saved whenever changes are made.
import { reactive } from "vue";
import { retrieveState, watchState } from "@sil/storage";
const state = reactive(
retrieveState(
{
count: 0,
},
"MY_STATE"
)
);
watchState(state, "MY_STATE");
Options
You can add the options to your retrieveState and watchState in order to change defaults.
| Option | Default | Description |
| ------- | ------- | -------------------------------------------------- |
| verbose | false
| Show logging in console whenever an action happens |
example:
const options = {
verbose: true,
};
const state = reactive(
retrieveState(
{
count: 0,
},
"MY_STATE",
options
)
);
watchState(state, "MY_STATE", options);