This repository has been archived by the owner on Jan 1, 2025. It is now read-only.
Can a function be shared as a state? #1270
Unanswered
The-End-Hero
asked this question in
Q&A
Replies: 1 comment
-
Yes, you can store functions in atoms and selectors, but there are some nuances you may need to accomodate. As the Atoms can be set to a function, as long as it is pure, but to do so you may need to use the updater form of setters. (e.g. For atom families you may also need to wrap in a function as well. Also take care not to use functions in values that may need to be serialized to check for value-equality, such as atom family parameters. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
like this:
export const changeItem = atom({ key: "changeItem", default: ()=>{}, });
Beta Was this translation helpful? Give feedback.
All reactions