deno.land / x / jotai@v1.8.4 / src / redux / atomWithStore.ts

atomWithStore.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import type { Action, AnyAction, Store } from 'redux'import { atom } from 'jotai'
export function atomWithStore<State, A extends Action = AnyAction>( store: Store<State, A>) { const baseAtom = atom(store.getState()) baseAtom.onMount = (setValue) => { const callback = () => { setValue(store.getState()) } const unsub = store.subscribe(callback) callback() return unsub } const derivedAtom = atom( (get) => get(baseAtom), (_get, _set, action: A) => { store.dispatch(action) } ) return derivedAtom}
jotai

Version Info

Tagged at
2 years ago