@payfit/unity-components
Version:
22 lines (21 loc) • 589 B
JavaScript
import { useCallback as e, useState as t } from "react";
//#region src/components/client-side-pagination/hooks/use-pagination.ts
function n({ isControlled: n = !1, pageCount: r, initialPage: i = 1, onPageChange: a }) {
let [o, s] = t(i), c = n ? i : o, l = c - 1, u = c + 1, d = e((e) => {
a && a(e, c, Math.sign(e - c)), s(Math.max(1, Math.min(r, e)));
}, [
c,
r,
a
]);
return {
currentPage: c,
previousPage: l,
nextPage: u,
goToPage: e((e) => {
d(e === "previous" ? c - 1 : e === "next" ? c + 1 : e);
}, [c, d])
};
}
//#endregion
export { n as usePagination };