Skip to content

Commit

Permalink
chore: Move urlKeys into the UseQueryStatesOptions type
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `UseQueryStatesOptions` is now generic over the key map
(the object containing parser definitions you pass to useQueryStates),
and is now a type rather than an interface.
  • Loading branch information
franky47 committed Oct 22, 2024
1 parent 7f965a6 commit 8950bc8
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions packages/nuqs/src/useQueryStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export type UseQueryStatesKeysMap<Map = any> = {
[Key in keyof Map]: KeyMapValue<Map[Key]>
}

export interface UseQueryStatesOptions extends Options {}
export type UseQueryStatesOptions<KeyMap extends UseQueryStatesKeysMap> =
Options & {
urlKeys: Partial<Record<keyof KeyMap, string>>
}

export type Values<T extends UseQueryStatesKeysMap> = {
[K in keyof T]: T[K]['defaultValue'] extends NonNullable<
Expand Down Expand Up @@ -74,13 +77,7 @@ export function useQueryStates<KeyMap extends UseQueryStatesKeysMap>(
clearOnDefault = false,
startTransition,
urlKeys = defaultUrlKeys
}: Partial<
UseQueryStatesOptions & {
// todo: Move into UseQueryStatesOptions in v2 (requires a breaking change
// to make the options type generic over the key map)
urlKeys: Partial<Record<keyof KeyMap, string>>
}
> = {}
}: Partial<UseQueryStatesOptions<KeyMap>> = {}
): UseQueryStatesReturn<KeyMap> {
type V = Values<KeyMap>
const stateKeys = Object.keys(keyMap).join(',')
Expand Down

0 comments on commit 8950bc8

Please sign in to comment.