Is it possible to initialise atomFamily multiple values at once?
See original GitHub issueFor example, I have an atomFamily which contains scores for cities and I access them by id. So, putting 1600 values to this family takes about 70-90ms, using loop:
for (const city of cities) {
set(cityScore$(city.id), city.rating);
}
But if I create simple map for such values, it takes like 0.3 − 0.4 ms:
for (const city of cities) {
map[city.id] = city.rating;
}
So, is there a way to initialise atomFamily values at once to speed up this initialisation process?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:11 (5 by maintainers)
Top Results From Across the Web
atomFamily(options) - Recoil
Like an atom, it may either be a value directly or a Promise , Loadable , wrapped value, or another atom/selector that represents...
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 >Jotai vs. Recoil: What are the differences? - LogRocket Blog
Jotai and Recoil both have their benefits. This article compares the state management libraries to help you decide what's best for you.
Read more >How to Manage Your React Application State With Recoil.js ...
And the following to our state/selectors.js file. The get function allows you to read and transform the value of one (or several) atom(s)....
Read more >Simplifying your application state management with Recoil
You can have multiple atoms, to split state, e.g. page, content, UI, etc., ... A hook that will reset the state to default...
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
The Recoil Sync Library documentation is now published. See this example initializing atoms from React props.
@kubejm @drarmstr thank you for your suggestions.
To clarify this case a bit — data coming from API and is part of page logic. So in my solution I have a selector with setter where I put values to
atomFamily
normalizing data in this way.So I am not sure if
initializeState
can help me here, as page is a few levels lower thanRecoilRoot
.Will take a look at
useRecoilTransaction()
then.