Recoil: [Question] Can atoms contain atoms in their values

Created on 15 May 2020  路  2Comments  路  Source: facebookexperimental/Recoil

In the talk, there was an array of ids and a memoized id => atom function. I think in the example the id array was regular react state, but let's pretend it was a recoil atom.

If you then delete an id, you have a caching issue with the memoize function

Is it possible/a good idea to have an atom whose value is an array of atoms?

I know a downside is that the component that has the array has to treat each element inside as a black box, since the rules of hooks will stop it reading their contents. But that might be okay

Most helpful comment

It's not an error to store an atom in an atom. It doesn't do anything special, though.

We are adding a feature soon where atoms will be deleted when no longer used, together with another hook that lets a component retain an atom without subscribing to it. These could be combined into a utility that gives you a list of IDs with automatic deletion of the individual atoms when they are removed from the list.

Currently you have to use the useResetRecoilState hook to delete atoms.

All 2 comments

It's not an error to store an atom in an atom. It doesn't do anything special, though.

We are adding a feature soon where atoms will be deleted when no longer used, together with another hook that lets a component retain an atom without subscribing to it. These could be combined into a utility that gives you a list of IDs with automatic deletion of the individual atoms when they are removed from the list.

Currently you have to use the useResetRecoilState hook to delete atoms.

Currently you have to use the useResetRecoilState hook to delete atoms.

@davidmccabe does useResetRecoilState actually delete the atoms themselves? The doc says it resets to the default, which seems like it鈥檇 still take some memory, at least to store the atom itself and the default value. (I know you said auto deletion is coming; just curious how useResetRecoilState works today.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

polemius picture polemius  路  3Comments

julienJean99 picture julienJean99  路  3Comments

robsoncezario picture robsoncezario  路  3Comments

thegauravthakur picture thegauravthakur  路  3Comments

ibnumusyaffa picture ibnumusyaffa  路  4Comments