Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Latest commit 6684987 Aug 14, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
packages (release) 0.0.4 Aug 14, 2019
.eslintrc.yml init Apr 15, 2018
.gitignore init Apr 15, 2018 (docs): readme Apr 15, 2018
package-lock.json init Apr 15, 2018
package.json init Apr 15, 2018

Unstated Persist

unstated container w/ persistence


Usage is simple, replace Container with PersistContainer and add persist config as a class property

import { PersistContainer } from 'unstated-persist'
import localForage from 'localforage'

type CounterState = {
  count: number

class CounterContainer extends PersistContainer<CounterState> {
  persist = {
    key: 'counter',
    version: 1,
    storage: localForage,
 // ...


Class inheritance are you crazy?

Well it works, and its tiny and simple. Risk of inheritance collision / confusion is minimal in this case.


In the future we will add redux-persist like migrations / transforms. For now, changing persist version will simply clobber stored state.


An example of how PersistGate might be implemented lives here. However it is so simple, I expect in most cases components will their own gating. Something like:

import { Subscribe } from 'unstated'
import { isBootstrapped } from 'unstated-persist'


<Subscribe to={[containers]}>
  {(...containers) => {
    if (!containers.every(isBootstrapped)) return <Loading />
    return <App />
You can’t perform that action at this time.