import Pagination from '@material-ui/lab/Pagination';
const [page, handlePage] = usePaginate()
<Pagination page={page} onChange={handlePage} />
Last active
July 11, 2021 15:37
-
-
Save izszzz/eef01981d1b34596e1f377ae1c942627 to your computer and use it in GitHub Desktop.
React usePaginate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useCallback, useState } from "react"; | |
const usePaginate = (): [ | |
number, | |
(_event: React.ChangeEvent<unknown>, value: number) => void | |
] => { | |
const [page, setPage] = useState(1); | |
const onPage = useCallback( | |
(_event: React.ChangeEvent<unknown>, value: number) => setPage(value), | |
[] | |
); | |
return [page, onPage]; | |
}; | |
export default usePaginate; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment