@thibault.sh/hooks
Version:
A comprehensive collection of React hooks for browser storage, UI interactions, and more
16 lines (14 loc) • 728 B
TypeScript
/**
* Hook for managing state persisted in URL query parameters
* @param key - The query parameter key
* @param initialValue - The initial value to use if the parameter doesn't exist
* @param options - Configuration options
* @param options.serialize - Function to convert value to string (default: JSON.stringify)
* @param options.deserialize - Function to parse string back to value (default: JSON.parse)
* @returns A tuple containing the current value and a setter function
*/
declare function useQueryParamsState<T>(key: string, initialValue: T, options?: {
serialize?: (value: T) => string;
deserialize?: (value: string) => T;
}): [T, (value: T | ((val: T) => T)) => void];
export { useQueryParamsState };