-
In my source code, there are so many weak maps from an object to an atom. I'm not sure if the jotai could add it as the builtin utility. |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
Nov 7, 2023
Replies: 1 comment 9 replies
-
I have been interested in the idea of export function weakAtomFamily(initializeAtom) {
const atoms = new WeakMap();
return (obj) => {
if (!atoms.has(obj)) {
atoms.set(obj, initializeAtom(obj));
}
return atoms.get(obj);
};
} Maybe, it's better in a recipe. |
Beta Was this translation helpful? Give feedback.
9 replies
Answer selected by
himself65
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have been interested in the idea of
weakAtomFamily
. It can be the Jotai way.Would it be pretty simple?
Maybe, it's better in a recipe.
(tbh, I'd like to move atomFamily to recipes in docs, if possible.)