Can a primitive atom hold a function? #1238
-
I'd like to store a function in a primitive atom, but Jotai wants to call this function. Can functions be stored in an atom? What is the intended use of functions passed to atom(fn)? This works: atom(() => fn) |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
Jun 18, 2022
Replies: 1 comment
-
You need to wrap with an object. const fnAtom = atom({ fun: () => 'hello' })
It doesn't create a primitive atom. It creates a read-only atom. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
AjaxSolutions
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to wrap with an object.
It doesn't create a primitive atom. It creates a read-only atom.