Write only atom that returns (prevState) => {} - setAction #2553
Answered
by
dai-shi
AlekseyP18
asked this question in
Q&A
-
Hello, I am new in using jotai user) const write = ....; const [, setUser] = useAtom(userWriteAtom); const updateUser = (newUser) => setUser(prevUser => ({ ...prevUser, ...newUser })); |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
May 13, 2024
Replies: 1 comment 1 reply
-
There are some ways depending on your requirement with the write-only atom, but this should help: const userWriteAtom = atom(null, (get, set, arg) => {
const prevUser = get(currentUserAtom);
const nextUser = typeof arg === 'function' ? arg(prevUser) : arg;
set(currentUserAtom, nextUser);
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
AlekseyP18
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are some ways depending on your requirement with the write-only atom, but this should help: