Way to get molecules imperatively #55
-
I am looking for a way to get molecule's actual state from imperative callbacks similar to jotai's My experiments lead me to following snippet: const injector = useInjector();
const scopes = useScopes();
const getMolecule = useCallback(
<T>(mol: MoleculeOrInterface<T>) => injector.get(mol, ...scopes),
[injector, scopes],
); and passing Is this a correct way (assuming mostly implicit scopes inside relative component)? |
Beta Was this translation helpful? Give feedback.
Answered by
loganvolkers
Mar 27, 2024
Replies: 1 comment
-
That will work, but keep in mind that calling Using |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
alexlag
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That will work, but keep in mind that calling
get
on the injector is not the same as callinguse
.Using
useMolecule
is still recommended for most cases since it handles the subscription lifecycle for you automatically.