Skip to content

Instantly share code, notes, and snippets.

@iamashiqur
Created December 10, 2024 06:57
Show Gist options
  • Select an option

  • Save iamashiqur/993dfc8d5d76cc0c415d60287424b9a7 to your computer and use it in GitHub Desktop.

Select an option

Save iamashiqur/993dfc8d5d76cc0c415d60287424b9a7 to your computer and use it in GitHub Desktop.
Pagination hook for mange pagination
import { useState } from 'react'
const usePagination = (initialPage: number = 1, initialLimit: number = 10) => {
const [currentPage, setCurrentPage] = useState<number>(initialPage)
const [pageLimit, setPageLimit] = useState<number>(initialLimit)
const handlePageChange = (page: number) => {
setCurrentPage(page)
}
const handlePageLimitChange = (limit: number) => {
setPageLimit(limit)
}
return {
currentPage,
pageLimit,
handlePageChange,
handlePageLimitChange
}
}
export default usePagination
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment