Skip to content

Commit 33a40b0

Browse files
committed
fix useAtomsSnapshot
1 parent 9661e6f commit 33a40b0

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

src/devtools/useAtomsSnapshot.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@ export function useAtomsSnapshot(scope?: Scope): AtomsSnapshot {
1818

1919
const [store, devStore] = scopeContainer
2020

21-
const [atoms, setAtoms] = useState(devStore.atoms)
21+
const [atomsSnaphost, setAtomsSnaphost] = useState<AtomsSnapshot>(new Map())
2222
useEffect(() => {
23-
const callback = () => setAtoms(devStore.atoms)
23+
const callback = () => {
24+
const { atoms } = devStore
25+
const atomToAtomValueTuples = atoms
26+
.filter((atom) => !!store[DEV_GET_MOUNTED]?.(atom))
27+
.map<[Atom<unknown>, unknown]>((atom) => {
28+
const atomState =
29+
store[DEV_GET_ATOM_STATE]?.(atom) ?? ({} as AtomState)
30+
return [atom, atomState.v]
31+
})
32+
setAtomsSnaphost(new Map(atomToAtomValueTuples))
33+
}
2434
const unsubscribe = devStore.subscribe(callback)
2535
callback()
2636
return unsubscribe
27-
}, [devStore])
37+
}, [store, devStore])
2838

29-
const atomToAtomValueTuples = atoms
30-
.filter((atom) => !!store[DEV_GET_MOUNTED]?.(atom))
31-
.map<[Atom<unknown>, unknown]>((atom) => {
32-
const atomState = store[DEV_GET_ATOM_STATE]?.(atom) ?? ({} as AtomState)
33-
return [atom, atomState.v]
34-
})
35-
return new Map(atomToAtomValueTuples)
39+
return atomsSnaphost
3640
}

0 commit comments

Comments
 (0)