@commercetools-uikit/hooks
Version:
A collection of React hooks used across some of the UI-Kit components.
19 lines (18 loc) • 632 B
TypeScript
import sortBy from 'lodash/sortBy';
export interface TItem {
id: string;
}
export type TSortDirection = 'asc' | 'desc';
export type TSortingState<Item extends TItem = TItem> = {
items: Item[];
sortedBy?: string;
sortDirection?: TSortDirection;
};
export type TSortingFn = typeof sortBy;
declare const useSorting: <Item extends TItem = TItem>(items: Item[], field?: string, sortDirection?: TSortDirection, sortingFunction?: TSortingFn) => {
items: Item[];
sortedBy: string | undefined;
sortDirection: TSortDirection | undefined;
onSortChange: (fieldKey: string) => void;
};
export default useSorting;