Skip to content

Unexpected rerenders on derived atom #2714

Answered by rothsandro
nocksock asked this question in Q&A
Discussion options

You must be logged in to vote

If you change an item, it updates the atom of that list item (atom(listItem)).

The openItemAtomsAtom depends on all atom(listItem)s, so it will recompute whenever any item atom value changes, which triggers a re-render of the Open list component. And as mentioned by dmaskasky, React will then re-render all child components unless there are wrapped in React.memo.

The itemAtomsAtom on the other hand only depends on itemsAtom, which is never updated. It creates the individual item atoms but doesn't depend on them. And because of that, itemAtomsAtom isn't recomputed when a single item atom changes. And that's why the All list component doesn't re-render when changing a single item.

Hope it he…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@nocksock
Comment options

@dmaskasky
Comment options

@nocksock
Comment options

@rothsandro
Comment options

Answer selected by nocksock
@rothsandro
Comment options

@nocksock
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants