Skip to content

Instantly share code, notes, and snippets.

View ricosandyca's full-sized avatar
🎧

Rico Sandyca ricosandyca

🎧
View GitHub Profile
@ricosandyca
ricosandyca / use-query-state.ts
Last active January 23, 2024 04:28
React Hook - Query State
import { useCallback, useMemo } from 'react';
import { useSearchParams } from 'react-router-dom';
// helper types
export type Nullable<T> = T | undefined | null;
export type NullableObject<T extends object> = { [K in keyof T]?: T[K] | null };
export type QueryStateValue = string | number | boolean;
export type UseQueryStateSetterFunctionType<T = any> = (prev: T) => T;
export type UseQueryStateSetterType<T = any> =
| T