@domonda/query-params
Version:
Useful but simple query params manipulator for React.
31 lines (30 loc) • 999 B
TypeScript
/**
*
* useQueryParams
*
*/
import { QueryModel } from './queryParams';
export interface UseQueryParamsProps<T, S> {
/**
* Parsed values will update only when the current pathname matches `onPathname`.
*/
onPathname?: string;
/**
* Get the params once (only on mount).
*/
once?: boolean;
/**
* Disables replacing the URL to match exactly the actual query paramaters.
*/
disableReplace?: boolean;
/**
* Selects a part of the result to return and updates only when the selected result changes.
*/
selector?: (params: T) => S;
}
export declare type UseQueryParamsResult<T, S> = [S, (selectedParmasOrUpdater: Partial<T> | ((currSelectedParams: T) => Partial<T>)) => void];
/**
* Parses the current URL query string following the `model`.
* Updating the params on every location change.
*/
export declare function useQueryParams<T, S = T>(model: QueryModel<T>, props?: UseQueryParamsProps<T, S>): UseQueryParamsResult<T, S>;