UNPKG

@payfit/unity-components

Version:

22 lines (21 loc) 551 B
import { useCallback as e, useState as t } from "react"; //#region src/components/pagination/hooks/use-pagination-state.ts function n({ pageCount: n, initialPage: r = 1, onPageChange: i }) { let [a, o] = t(r), s = a - 1, c = a + 1, l = e((e) => { i && i(e, a, Math.sign(e - a)), o(Math.max(1, Math.min(n, e))); }, [ a, n, i ]); return { currentPage: a, previousPage: s, nextPage: c, goToPage: e((e) => { l(e === "previous" ? a - 1 : e === "next" ? a + 1 : e); }, [a, l]) }; } //#endregion export { n as usePaginationState };