Skip to content

Instantly share code, notes, and snippets.

@kokotom
kokotom / useStateOnlySearchParams.tsx
Created December 24, 2022 15:12
A hook for remix to read and update search params without causing navigation.
import {useCallback, useState} from 'react'
import {createSearchParams} from 'react-router-dom'
import {useLocation} from '@remix-run/react'
export type ParamKeyValuePair = [string, string]
type URLSearchParamsInit =
| string
| ParamKeyValuePair[]
| Record<string, string | string[]>