Skip to content
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

refactor(Grid): move setState outside of loops to avoid unnecessary redraws #583

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ class Grid extends React.Component<
/>;

this.cardList.push(card as unknown as Card);
this.setState({ cards: this.cardList });
}

// TODO: this isn't currently used, but it will be used for sorting (based on the SortBox component)
Expand Down Expand Up @@ -210,6 +209,7 @@ class Grid extends React.Component<
});
}
}
this.setState({ cards: this.cardList });

// First result is null or -1 so it coerces to 1
const currentPage = this.requestPage > -1 && this.requestPage ? this.requestPage : 1;
Expand Down Expand Up @@ -244,6 +244,7 @@ class Grid extends React.Component<
});
}
}
this.setState({ cards: this.cardList });
break;

// Don't need to return a page number because
Expand All @@ -270,6 +271,7 @@ class Grid extends React.Component<
});
}
}
this.setState({ cards: this.cardList });

// First request is null, so coerces to 1
const currentPage = this.requestPage > -1 && this.requestPage ? this.requestPage : 1;
Expand Down Expand Up @@ -303,6 +305,7 @@ class Grid extends React.Component<
});
}
}
this.setState({ cards: this.cardList });

// First request is null, so coerces to 1
const currentPage = this.requestPage > -1 && this.requestPage ? this.requestPage : 1;
Expand All @@ -323,6 +326,7 @@ class Grid extends React.Component<
}
if (snippets && snippets.length) {
snippets.forEach((snippet) => this.appendCard(snippet, "snippet", activeTab));
this.setState({ cards: this.cardList });
}
}}

Expand Down