Simple store that can be hooked into React.

Source code is hosted on GitHub

yarn add @corets/store

Seamless React integration is shipped in a separate package:

There is a version of this package that syncs directly to the localStorage:


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 })


Retrieve everything from the store:



Replace everything in the store:

store.set({ foo: "bar" })


Update store by merging new and old state:

store.put({ some: "data" })


Listen to changes:

store.listen((value) => console.log(value))

Listen to changes with a custom differ:

const differ = (oldValue, newValue) => true

store.listen((value) => console.log(value), { differ })

Listen to a subset of data, using a custom mapper:

const mapper = {value} => ({  })

store.listen((value) => console.log(value), { mapper })


Convenience method for people used to React's useState syntax:

import { createStore } from "@corets/store"

const [store, setStore] = createStore({ foo: "bar" }).use()

Last updated