# give/4.17.0/src/Views/Components/ListTable/hooks/useResetPage.ts

GiveWP – Donation Plugin and Fundraising Platform, version 4.17.0. 16 lines.

- Page: https://pluginprobe.com/plugins/give/4.17.0/code/src/Views/Components/ListTable/hooks/useResetPage.ts
- Raw: https://pluginprobe.com/plugins/give/4.17.0/raw/src/Views/Components/ListTable/hooks/useResetPage.ts
- Modified: 2023-01-18T19:19:38+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/give/4.17.0/code/src/Views/Components/ListTable/hooks/useResetPage.ts#L10-L20`.

```typescript
import {useEffect} from 'react';

export const useResetPage = (data, page, setPage, filters) => {
    //if we're displaying a non-existent page (like after deleting an item), go to the last available page
    useEffect(() => {
        if (data?.totalPages && page > data.totalPages) {
            setPage(data.totalPages);
        }
    }, [data]);

    //go back to the first page whenever filters change
    useEffect(() => {
        setPage(1);
    }, [filters]);
};

```
