hooks/useDataTableQueryState.ts

polar · clients/apps/web/src/hooks/useDataTableQueryState.ts · typescript · Apache-2.0
ui, tag:embed-classified

Syncs DataTable pagination and sorting with URL query params for shareable views.

// Source: https://github.com/polarsource/polar | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
'use client'

import {
  DataTablePaginationState,
  DataTableSortingState,
  sortingQueryParamToState,
  sortingStateToQueryParam,
} from '@/utils/datatable'
import { functionalUpdate, OnChangeFn } from '@tanstack/react-table'
import {
  parseAsArrayOf,
  parseAsInteger,
  parseAsString,
  useQueryStates,
} from 'nuqs'
import { useCallback, useMemo } from 'react'

interface UseDataTableQueryStateProps {
  defaultSorting?: DataTableSortingState
  defaultPageSize?: number
}

interface DataTableQueryState {
  pagination: DataTablePaginationState
  setPagination: OnChangeFn<DataTablePagina

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key