@future-widget-lab/ui-filters
Version:
A set of primitives for handling filters through search parameters in React applications.
43 lines (42 loc) • 1.57 kB
TypeScript
import type { Filters } from '../../types/filters.type';
export type DeserializeFiltersOptions = {
/**
* @description
* The serialized representation of the filters.
*/
serializedFilters: string | null;
/**
* @description
* Use this helper to create a valid filters collection out of the search parameter value where filters are stored.
*
* Defaults to flatted's `parse` if not present (See https://www.npmjs.com/package/flatted).
*/
deserializer?: (value: string) => Filters;
/**
* A hook that is fired when before the filters collection is deserialized.
*
* Consumers can use this to perform any kind of side-effects or validation.
*/
onBeforeDeserializer?: () => void;
/**
* A hook that is fired when after the filters collection is deserialized.
*
* Consumers can use this to perform any kind of side-effects.
*/
onAfterDeserializer?: (filters: Filters) => void;
/**
* A hook that is fired when an error occurs during the deserialization of the filters collection.
*
* Consumers can use this to perform any kind of side-effects.
*/
onDeserializerError?: (error: Error) => void;
};
/**
* @description
* Use this helper to perform the filters deserialization.
*
* Return a filters collection given a search params set and a search param name.
*
* Returns an empty collection if no search parameter is found or an error occurs.
*/
export declare const deserializeFilters: (options: DeserializeFiltersOptions) => Filters;