Local Storage Store
Simple observable store that can be subscribed to, in React, using Hooks. State is automatically synced to the localStorage.
yarn
npm
yarn add @corets/local-storage-store
npm install --save @corets/local-storage-store
Seamless React integration is shipped in a separate package:
This is a
localStorage
version of this package:Example of how to use this package in React:
import React from "react"
import { createLocalStorageStore } from "@corets/local-storage-store"
import { useStore } from "@corets/use-store"
const Example = () => {
const counterStore = useStore(() => createLocalStorageStore("storageKey", { counter: 0 }))
const increment = () => counterStore.set({ counter: counterStore.get().counter + 1 })
return (
<div>
<button onClick={increment}>{counterStore.get().counter}</button>
</div>
)
}
Create a new observable store:
import { createLocalStorageStore } from "@corets/local-storage-store"
const store = createLocalStorageStore("storageKey", { some: "data" })
Last modified 1yr ago