Replies: 2 comments
-
Alternative: export function createAtoms(api:Api) {
const atom1 = atom<string[]>({
key: `app.namespace.atom1`,
default: api.getInitialValue(), // This is a promise
});
const selector1 = selector<string[]>({
key: `app.namespace.selector1`,
get: ({ get }) => get(atom1),
set: async ({ set }, newValue) => {
await api.logEventWithValue(newValue);
set(atom1, newValue);
},
});
return { atom1, selector1 };
} |
Beta Was this translation helpful? Give feedback.
-
While |
Beta Was this translation helpful? Give feedback.
-
Hello!
We're evaluating recoil and are excited about it's async handling!
However, like many projects, we need to pass in an object encapsulating our API.
Because there is no built in mechanism for passing in dependencies, the only way I see to do it is to close over the atoms when they are instantiated.
The pattern I have landed on looks like this:
Is there a better way to do this? Are there dragons to look out for 🐉 ?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions