Skip to content

Add reaction cause rerender all PostsExcerpts #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
moh1434 opened this issue Jan 17, 2023 · 0 comments
Open

Add reaction cause rerender all PostsExcerpts #4

moh1434 opened this issue Jan 17, 2023 · 0 comments

Comments

@moh1434
Copy link

moh1434 commented Jan 17, 2023

In 08_lesson.
clicking add reaction button will cause all <PostsExcerpt> components to be re rendered because in <PostsList> we are using all posts from useGetPostsQuery
const PostsList = () => { const { data: posts, isLoading, isSuccess, isError, error } = useGetPostsQuery('getPosts')
to fix this performance issue we could select only posts.ids from it.
Like this:
const PostsList = () => { const { postsIds, isLoading, isSuccess, isError, error } = useGetPostsQuery('getPosts', { selectFromResult: ({ data, isLoading, isSuccess, isError, error }) => ({ postsIds: data?.ids, isLoading, isSuccess, isError, error, }), })
After this fix only one <PostsExcerpt> component will be re rendered.

Before:
1
After:
2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant