AtomFamily no way to separate key and init value?
See original GitHub issueMaybe I’m missing something here, but it looks like atomFamily sets map key AND the atom value directly based from the param/ key and there’s no way to pass a key and value separately. Yes, its not 100% 1:1 since you can do get calls and derivative logic.
from atomFamily.ts:50-52
const newAtom = initializeAtom(param)
atoms.set(param, [newAtom, Date.now()])
return newAtom
So say I want to put an object in the atomFamily, I would need to have access to the entire object any time I want to access the atom. Doesn’t this make atomFamily nearly pointless?
How I would expect it to work is that I can pass in say a string key and that would give me access to the object.
Alternatively if there’s another way to create atoms dynamically that you can
- iterate over (doing it now inelegantly by tracking string IDs in another atom)
- access single atom by some ID/ key
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Question: atomFamily and key. #183 - GitHub
Is there any way to get a element by key? How does the key applies on a atomFamily? Does atomFamily supports a dynamic...
Read more >atomFamily(options) - Recoil
key - A unique string used to identify the atom internally. This string should be unique with respect to other atoms and selectors...
Read more >How to get all elements from an atomFamily in recoil?
You have to track all ids of the atomFamily to get all members of the family. Keep in mind that this is not...
Read more >atomFamily — Jotai, primitive and flexible state management ...
Internally, atomFamily is just a Map whose key is a param and whose value is an atom config. Unless you explicitly remove unused...
Read more >Jotai vs. Recoil: What are the differences? - LogRocket Blog
Atoms in Jotai do not have the key property, so instead of const ... In Recoil, the initial value is set in the...
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 Free
Top 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
Yes, no, yes.
Would calling it like this
useAtom(selectAtom(bigAtom
let you solely subscribe to changes in the small atom and ignore all changes to bigAtom?Also, wouldn’t it have to look like this?
or does selectAtom automatically anything into a subscribable atom without the source having to be an atom beforehand?