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
})
If #854 is successfully merged, we would like to consider exposing
unstable_createStore.