Replies: 3 comments 2 replies
-
Recoil supplies us with the building blocks to build whatever data structure we choose. The key part is getting the atom structure correct and handling state operations. Here is an example of how you can accomplish atomizing this complex data structure.
Selectors for deriving state from atoms.
Custom hooks for managing adding and remvoing todo's.
This may not be the best approach for you, but it is just an example of how you can structure your atoms, derive state from atoms with selectors, and use hooks for adding/removing todos. The Recoil team will be able to explain this better and correct me on incorrect usages. |
Beta Was this translation helpful? Give feedback.
-
See also #1164 |
Beta Was this translation helpful? Give feedback.
-
How would one atomize complex structures say 3-4 levels deep ? Would it be possible to have nested atom families of families ? Thanks. EG.
|
Beta Was this translation helpful? Give feedback.
-
This is a simpified version of a complex data strcture that I have:
To leverage the power of recoil, I have broken down the structure into various atom families, and i'm linking them through unique IDs:
But breaking the structure like this adds a lot of complexity to the code. For example, when I add a new
todo
to the list, I have to iterate over the list oftags
and create tag atoms.Similarly when I remove a
todo
I have to iterate over all the internaltag
atoms and remove them as well.This gets more complex the deeper the nesting is.
Is there a best practice for atomizing a deeply nested structure like this?
Beta Was this translation helpful? Give feedback.
All reactions