Skip to content

Commit

Permalink
use react useEffect hook
Browse files Browse the repository at this point in the history
  • Loading branch information
kaperoo committed Dec 14, 2023
1 parent da6b7db commit 7513ea7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/table/table.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ const Table = React.memo((props: TableProps): React.ReactElement => {
} = props;

const count = maxShots > totalDataCount ? totalDataCount : maxShots;
const pageToUse = count > page * resultsPerPage ? page : 0;
if (page !== pageToUse) onPageChange(pageToUse);

React.useEffect(() => {
console.log('page', page);
if (count < page * resultsPerPage) {
onPageChange(0);

Check warning on line 101 in src/table/table.component.tsx

View check run for this annotation

Codecov / codecov/patch

src/table/table.component.tsx#L101

Added line #L101 was not covered by tests
}
}, [count, page, resultsPerPage, onPageChange, data]);

const defaultColumn: Partial<ColumnDef<RecordRow>> = React.useMemo(
() => ({
Expand Down Expand Up @@ -286,7 +291,7 @@ const Table = React.memo((props: TableProps): React.ReactElement => {
component="div"
count={count}
onPageChange={(e, page) => onPageChange(page)}
page={pageToUse}
page={count > page * resultsPerPage ? page : 0}
rowsPerPage={resultsPerPage}
rowsPerPageOptions={maxShots === 50 ? [10, 25, 50] : [10, 25, 50, 100]}
onRowsPerPageChange={(event) =>
Expand Down

0 comments on commit 7513ea7

Please sign in to comment.