Skip to content

[RFC] unstable_createStore #861

@dai-shi

Description

@dai-shi

If #854 is successfully merged, we would like to consider exposing unstable_createStore.

import { atom, Provider, unstable_createStore } from 'jotai'

const countAtom = atom(0)
const store = unstable_createStore()

const App = () => (
  <Provider unstable_createStore={() => store}>
    ...
  </Provider>
)

// read atom value outside React
const value = store.get(countAtom)

// write atom value outside React
store.set(countAtom, 1)
store.set(countAtom, (c) => c + 1)

// subscribe to atom change outside React
const unsub = store.sub(countAtom, () => {
  console.log('countAtom can be changed')
  const value = store.get(countAtom) // this can be the same value as the previous one
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions