Skip to content

Question about useReducerAtom and derived atoms #2672

Answered by rothsandro
mo-lon asked this question in Q&A
Discussion options

You must be logged in to vote

Your useReducerAtom hook reads the whole atom state, that's why the component re-render. Replace it with useSetAtom which doesn't return the atom value:

- const [, setState] = useAtom(anAtom);
+ const setState = useSetAtom(anAtom);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mo-lon
Comment options

Answer selected by mo-lon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants