How to nest atomfamily of atomfamilies ? #1965
Replies: 7 comments
-
Try to «normalize» your state by storing all entities in separate atomFamilies, keepin only Id references in parent structures and then selecting them by Ids. Like this: const frames$ = atomFamily({
key: "@frame",
default: null,
});
interface Video {
frameIds: string[];
}
const videos$ = atomFamily({
key: "@video",
default: null,
});
const framesByVideo = selectorFamily$({
key: "@FramesByVideo",
get(videoId: string) {
return ({ get }) => {
const video = get(videos$(videoId));
const frames = video.frameIds.map((frameId) => get(frames$(frameId)));
return frames;
};
},
}); |
Beta Was this translation helpful? Give feedback.
-
Thank U for the detailed answer ! |
Beta Was this translation helpful? Give feedback.
-
How would one completely remove an atom from a atom family ? |
Beta Was this translation helpful? Give feedback.
-
@GuacheSuede by resetting it to default value or by setting it to undefined. |
Beta Was this translation helpful? Give feedback.
-
@sergiybabich Is a way to remove/filter it to reduce copy operations ? |
Beta Was this translation helpful? Give feedback.
-
@GuacheSuede what exactly do you mean? |
Beta Was this translation helpful? Give feedback.
-
@sergiybabich Is it possible to remove a atom from a existing atom family without needed to reset it first ? |
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.
All reactions