-
-
Notifications
You must be signed in to change notification settings - Fork 256
Description
Let's move the discussion from #1066 here.
The idea is to introduce a callback as an adapter prop that will be called after the URLSearchParams have been merged:
nuqs/packages/nuqs/src/lib/queues/throttle.ts
Lines 177 to 183 in 97390a5
| for (const [key, value] of items) { | |
| if (value === null) { | |
| search.delete(key) | |
| } else { | |
| search.set(key, value) | |
| } | |
| } |
It should run before the URLSearchParams object is sent to the adapter for updating the URL.
This can be used to implement a few interesting behaviours:
- Sorting the search params in some way (eg: alphabetically by key)
- Injecting / removing values
- Other kinds of processing
Example API:
<NuqsAdapter
processUrlSearchParams={(search) => {
const entries = Array.from(params.entries())
entries.sort(([a], [b]) => a.localeCompare(b))
return new URLSearchParams(entries)
}}
>
{ children }
</NuqsAdapter>Message history
(like a callback function to process URLSearchParams after applying updates for alphabetical sorting).
Is this feature planned? We're definitely looking for this feature specifically. (alphabetical sorting of parameters)
Edit: or a callback where we can do it ourselves.
Originally posted by @Multiply in #1066 (comment)
@Multiply would you like to try your hand at a PR?
Was already looking into the recent introduction of global default config.
Do you have a preference for where the middleware should be called?
Originally posted by @Multiply in #1066 (comment)