Vize

use-offset-pagination

Offset-based pagination state.

Package @vizejs/composable/use-offset-pagination
Own the source vize lib pull composable:use-offset-pagination
Runtime exports useOffsetPagination
Gzip budget 1280 B

Usage

import { useOffsetPagination } from "@vizejs/composable/use-offset-pagination";

Runtime contract

Utility Category Stability SSR Hydration Cleanup Targets Host globals Uses
useOffsetPagination state experimental safe stable reactive-scope web, server, worker, native, desktop, terminal — —

API

useOffsetPagination

Offset-based pagination state. The page is clamped into [1, pageCount] on every read and write, so shrinking total or growing pageSize never leaves the cursor past the end. Writable page/pageSize refs are updated in place for two-way binding. Callbacks fire after the corresponding value settles. Synchronous state: SSR-safe; watchers follow the owning scope.

function useOffsetPagination(options: UseOffsetPaginationOptions = {}): OffsetPagination
const { currentPage, pageCount, next, offset } = useOffsetPagination({ total, pageSize: 20 });

Types

OffsetPaginationInfo

Page information passed to the useOffsetPagination callbacks.

Member Type Description
currentPage number One-based current page.
currentPageSize number Items per page.
pageCount number Number of pages (at least one).

UseOffsetPaginationOptions

Options for useOffsetPagination.

Member Type Description
total? MaybeRefOrGetter<number> Total number of items. Reactive.
page? MaybeRef<number> One-based current page. Pass a writable ref for two-way binding.
pageSize? MaybeRef<number> Items per page. Pass a writable ref for two-way binding.
onPageChange? (info: OffsetPaginationInfo) => void Called after the current page changes.
onPageSizeChange? (info: OffsetPaginationInfo) => void Called after the page size changes.
onPageCountChange? (info: OffsetPaginationInfo) => void Called after the page count changes.

OffsetPagination

Pagination state and controls returned by useOffsetPagination.

Member Type Description
currentPage WritableComputedRef<number> One-based current page, always within [1, pageCount]. Writable.
currentPageSize WritableComputedRef<number> Items per page, at least one. Writable.
pageCount ComputedRef<number> Number of pages (at least one).
offset ComputedRef<number> Zero-based offset of the first item of the current page.
isFirstPage ComputedRef<boolean> Whether the current page is the first.
isLastPage ComputedRef<boolean> Whether the current page is the last.
prev () => void Go to the previous page (no-op on the first).
next () => void Go to the next page (no-op on the last).