"use client"; import { useState } from "react"; import { type OnChangeFn, type SortingState, type Updater, } from "@tanstack/react-table"; export const SKILLS_TABLE_EMPTY_ICON = ( ); /** * Small helper for supporting both controlled and uncontrolled table sorting. * * TanStack Table expects a `sorting` state + `onSortingChange` callback. * Some pages want to control this from the URL (shareable links), while others * are fine letting the table manage it internally. */ export const useTableSortingState = ( sorting: SortingState | undefined, onSortingChange: OnChangeFn | undefined, defaultSorting: SortingState, ): { resolvedSorting: SortingState; handleSortingChange: OnChangeFn; } => { const [internalSorting, setInternalSorting] = useState(defaultSorting); const resolvedSorting = sorting ?? internalSorting; const handleSortingChange: OnChangeFn = onSortingChange ?? ((updater: Updater) => { setInternalSorting(updater); }); return { resolvedSorting, handleSortingChange, }; };