Not possible to restore atoms created with atomFamily
See original GitHub issuegiven the atomFamily:
const testItem = atomFamily<number>({
key: 'testItem',
default: null
});
creating an item with set(testItem("myId"), 123)
triggers a call to
useTransactionObservation_UNSTABLE({atomValues, atomInfo, modifiedAtoms} => {
const list = [];
for (const modifiedAtom of modifiedAtoms) {
list.push({name: modifiedAtom, value: JSON.stringify(atomValues.get(modifiedAtom))});
}
saveStore(list)
});
with the key as testItem__"myId"
. When trying to restore that with
set({key: item.name}, JSON.parse(item.value));
it fails with error Missing definition for RecoilValue: "testItem__"myId""
Also atomValues.get(modifiedAtom)
always return nothing as atomValues is always empty.
Also there is an error in the documentation that says we should use modifiedAtom.key
. modifiedAtom
is a string though and therefore does not have key
property.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Reset state of atomFamily - reactjs - Stack Overflow
An atomFamily just creates a helper layer for a map of atoms. So internally, Recoil would also just iterate over every given atom...
Read more >Atom Family in Recoil for Statement Management — Nextjs
Firstly, you created a website that uses atoms for storing all the todos, and then you used a selector family for changing a...
Read more >atomFamily(options) - Recoil
Returns a function that returns a writeable RecoilState atom.
Read more >Simplifying your application state management with Recoil
A hook that will reset the state to default value given when creating the atom. As the useSetRecoilState , this hook will not...
Read more >Captain Atom - Wikipedia
Captain Atom is a superhero appearing in American comic books, first in the 1960s by Charlton Comics before being acquired in the 1980s...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Not yet, we had some pandemic-related delays, but still working on the persistence library.
This is why we hesitated a bit to publish the temporary persistence API… Yes, you can keep a map of atoms, though that is tricky with atomFamilies created dynamically. Internally, we actually used
setUnvalidatedAtomValues()
, which takes a key string. But, that’s going away and requires extra metadata in the atoms. I’m really excited about the new API and helper library in the works.