@@ -16,9 +16,10 @@ import {
16
16
} from './update-queue'
17
17
import { safeParse } from './utils'
18
18
19
- type KeyMapValue < Type > = Parser < Type > & {
20
- defaultValue ?: Type
21
- }
19
+ type KeyMapValue < Type > = Parser < Type > &
20
+ Options & {
21
+ defaultValue ?: Type
22
+ }
22
23
23
24
export type UseQueryStatesKeysMap < Map = any > = {
24
25
[ Key in keyof Map ] : KeyMapValue < Map [ Key ] >
@@ -135,33 +136,39 @@ export function useQueryStates<KeyMap extends UseQueryStatesKeysMap>(
135
136
} , [ keyMap ] )
136
137
137
138
const update = React . useCallback < SetValues < KeyMap > > (
138
- ( stateUpdater , options = { } ) => {
139
+ ( stateUpdater , callOptions = { } ) => {
139
140
const newState : Partial < Nullable < KeyMap > > =
140
141
typeof stateUpdater === 'function'
141
142
? stateUpdater ( stateRef . current )
142
143
: stateUpdater
143
144
debug ( '[nuq+ `%s`] setState: %O' , keys , newState )
144
145
for ( let [ key , value ] of Object . entries ( newState ) ) {
145
- const config = keyMap [ key ]
146
- if ( ! config ) {
146
+ const parser = keyMap [ key ]
147
+ if ( ! parser ) {
147
148
continue
148
149
}
149
150
if (
150
- ( options . clearOnDefault || clearOnDefault ) &&
151
+ ( callOptions . clearOnDefault ??
152
+ parser . clearOnDefault ??
153
+ clearOnDefault ) &&
151
154
value !== null &&
152
- config . defaultValue !== undefined &&
153
- ( config . eq ?? ( ( a , b ) => a === b ) ) ( value , config . defaultValue )
155
+ parser . defaultValue !== undefined &&
156
+ ( parser . eq ?? ( ( a , b ) => a === b ) ) ( value , parser . defaultValue )
154
157
) {
155
158
value = null
156
159
}
157
160
emitter . emit ( key , value )
158
- enqueueQueryStringUpdate ( key , value , config . serialize ?? String , {
159
- // Call-level options take precedence over hook declaration options.
160
- history : options . history ?? history ,
161
- shallow : options . shallow ?? shallow ,
162
- scroll : options . scroll ?? scroll ,
163
- throttleMs : options . throttleMs ?? throttleMs ,
164
- startTransition : options . startTransition ?? startTransition
161
+ enqueueQueryStringUpdate ( key , value , parser . serialize ?? String , {
162
+ // Call-level options take precedence over individual parser options
163
+ // which take precedence over global options
164
+ history : callOptions . history ?? parser . history ?? history ,
165
+ shallow : callOptions . shallow ?? parser . shallow ?? shallow ,
166
+ scroll : callOptions . scroll ?? parser . scroll ?? scroll ,
167
+ throttleMs : callOptions . throttleMs ?? parser . throttleMs ?? throttleMs ,
168
+ startTransition :
169
+ callOptions . startTransition ??
170
+ parser . startTransition ??
171
+ startTransition
165
172
} )
166
173
}
167
174
return scheduleFlushToURL ( router )
0 commit comments