Skip to content

Avoiding screen tearing requires passing snapshots+stores together? #657

Answered by dai-shi
stephenh asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, I didn't read everything, but one note is, to make it reactive, we useSnapshot and then pass a store.
Also, having key={} would really help in React. So, I'd assume author has id prop.

function AuthorList({ store }) {
  const snap = useSnapshot(store);
  return snap.authors.map(((a, i) => <AuthorView key={a.id} author={store.authors[i]} />)
});

It's a bit tricky but should work the best. (There should be other solutions.)
You also want to wrap AuthorView with React.memo.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@stephenh
Comment options

@dai-shi
Comment options

Answer selected by stephenh
Comment options

You must be logged in to vote
1 reply
@stephenh
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
2 participants