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.

Is it possible to initialise atomFamily multiple values at once?

See original GitHub issue

For 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
drarmstrcommented, Feb 22, 2022

The Recoil Sync Library documentation is now published. See this example initializing atoms from React props.

1reaction
sergiybabichcommented, Sep 15, 2021

@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 than RecoilRoot.

Will take a look at useRecoilTransaction() then.

Read more comments on GitHub >

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

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