usePaging

Returns the page number, page count and a method to set the current page for data objects that use dynamic loading.

Usage

This is an example of how you can bind the MUI Pagination component to a data objects paging:

import { Pagination as MuiPagination, PaginationProps } from "@mui/material";
import { DataObject } from "@olenbetong/appframe-data";
import { usePaging } from "@olenbetong/appframe-react";

export function Pagination({
  dataObject,
  ...props
}: PaginationProps & { dataObject: DataObject<any> }) {
  let { changePage, page, pageCount } = usePaging(dataObject);
  return (
    <MuiPagination
      count={pageCount}
      page={page + 1}
      onChange={(evt, newPage) => changePage(newPage - 1)}
      {...props}
    />
  );
}

API

Last updated

Was this helpful?