useSetAtom, useAtomCallback and the missing useGetAtom #1842
-
When manipulating atom from within a callback (without having to rerender when the atom change), we have currently several options: First to write the atom imperatively, we can use Then to read an atom imperatively, we have to use the My question is: Or in the same direction, why Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
useAtomValue is for useAtomCallback exists for rather historical reason. Its implementation is pretty simple. jotai/src/react/utils/useAtomCallback.ts Lines 8 to 17 in f05d9ed
|
Beta Was this translation helpful? Give feedback.
-
ok i get your point to match the I understand that hook much better now... So using
And using
Two more questions:
|
Beta Was this translation helpful? Give feedback.
useAtomValue is for
read
function, and useSetAtom is forwrite
function. But, they aren't symmetric by nature, because the API design is to followuseState
.useAtomCallback exists for rather historical reason. Its implementation is pretty simple.
jotai/src/react/utils/useAtomCallback.ts
Lines 8 to 17 in f05d9ed