Skip to content

Commit

Permalink
perf(grid): move setState outside of loops to avoid unnecessary red…
Browse files Browse the repository at this point in the history
…raws (#583)
  • Loading branch information
Delusoire authored Aug 28, 2023
1 parent 7d1ad06 commit bca9679
Showing 1 changed file with 5 additions and 1 deletion.
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

0 comments on commit bca9679

Please sign in to comment.