Store
Simple store that can be hooked into React.
Source code is hosted on GitHub
yarn add @corets/storenpm install --save @corets/storeSeamless React integration is shipped in a separate package:
useStoreThere is a version of this package that syncs directly to the localStorage:
createStore()
Creates a new instance of observable store:
import { createStore } from "@corets/store"
const store = createStore({ some: "data" })Create a new instance without the factory function:
import { Store } from "@corets/store"
const store = new Store({ some: "data" })Create a new instance with a custom differ:
import { createStore } from "@corets/store"
const differ = (oldValue, newValue) => true
const store = createStore({ some: "data" }, { differ })Store.get()
Retrieve everything from the store:
Store.set()
Replace everything in the store:
Store.put()
Update store by merging new and old state:
Store.listen()
Listen to changes:
Listen to changes with a custom differ:
Listen to a subset of data, using a custom mapper:
Store.use()
Convenience method for people used to React's useState syntax:
Last updated
Was this helpful?