UNPKG

@scaleway/use-query-params

Version:
31 lines (30 loc) 1.22 kB
import queryString from 'query-string'; type Options = { /** Set to true to push a new entry onto the history stack */ push: boolean; }; declare const parse: typeof queryString.parse; declare const stringify: typeof queryString.stringify; type QueryParamValue = string | number | boolean | null | undefined; type QueryParams = { [key: string]: QueryParamValue | QueryParamValue[]; }; declare const useQueryParams: <T extends QueryParams>() => { queryParams: T; /** * Replace the query params in the url. It erase all current values and put the new ones * * @param newParams - The values to set in the query string, overwriting existing one * @param options - Options to define behavior */ replaceQueryParams: (newParams: T, options?: Options) => void; /** * Set query params in the url. It merge the existing values with the new ones. * * @param nextParams - The values to add or update in the existing query string * @param options - Options to define behavior */ setQueryParams: (nextParams: Partial<T>, options?: Options) => void; }; export default useQueryParams; export { parse as parseQueryParams, stringify as stringifyQueryParams };