is there a difference between atomFamily default and selectorFamily get?
See original GitHub issueWas a bit confused by this two approaches.
const userInfoQuery = atomFamily({
key: 'UserInfoQuery',
default: async userID => {
const response = await myDBQuery({userID});
return response;
});
and
const userInfoQuery = selectorFamily({
key: 'UserInfoQuery',
get: userID => async () => {
const response = await myDBQuery({userID});
return response;
},
});
They both will be recomputed if we pass new userID
.
So if we don’t need get
or set
then we can use atomFamily
?
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
atomFamily(options) - Recoil
default - The initial value of the atom. Like an atom, it may either be a value directly or a Promise , Loadable...
Read more >What is the use case of atomFamily in recoil? - Stack Overflow
The Cell component uses useRecoilState and find its specific Atom by accessing the main dictionary using the key it got passed as a...
Read more >atomFamily() - Recoil 中文文档
default : The initial value of the atom. It may either be a value directly, a RecoilValue or Promise that represents the default...
Read more >atomFamily — Jotai, primitive and flexible state management ...
initializeAtom is function that can return any kind of atom ( atom() ... To reproduce the similar behavior to Recoil's atomFamily/selectorFamily, ...
Read more >Use selectorFamily to take arguments in your Recoil selectors
[0:25] To start, we're going to store our sortValue in an atom. Again, we'll give it the key sortValue, and we will give...
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
Both expose the same interface and both may be read/writeable (if the selector provides a
set
).Atoms represent and maintain state while selectors represent functions. Use atoms when you need state and a selector when it is derived from other state or async requests.
In reality, atoms with asynchronous defaults are actually implemented by wrapping with a selector. It’s provided as a convenience. So, to your original question, the
atomFamily
would actually construct selectors to get the async data as well as atoms with state that then go unused if you never set the atom.@drarmstr hmm interesting. In the docs we have this selector
It was missleading to see the
get
there even though it is not used. Would it be okay to remove it? Have this pr here: https://github.com/facebookexperimental/Recoil/pull/234