question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not possible to restore atoms created with atomFamily

See original GitHub issue

given 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:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
drarmstrcommented, Jul 22, 2020

Not yet, we had some pandemic-related delays, but still working on the persistence library.

1reaction
drarmstrcommented, Jun 8, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found