-
-
Notifications
You must be signed in to change notification settings - Fork 175
Open
Description
I am using the recent useSearchParams hook to manage my query parameters in my application but it seems that there is a mismatch between what the documentation writes about how to use the hook and TypeScript that yells because of a void type when setting new params.
I am using this structure from the documentation:
// modify a specific search parameter
setSearchParams((prev) => {
prev.set('tab', 'settings');
});
with something like this:
setSearchParams((prev) => {
prev.set(name, val);
});
where name and val are the variables for the name of the query param to modify and val the value used for the modification.
In this context, TypeScript marks (prev) => as an error with this log:
Argument of type '(prev: URLSearchParams) => void' is not assignable to parameter of type 'string | URLSearchParams | string[][] | Record<string, string> | ((prev: URLSearchParams) => string | URLSearchParams | string[][] | Record<...> | undefined) | undefined'.
Type '(prev: URLSearchParams) => void' is not assignable to type '(prev: URLSearchParams) => string | URLSearchParams | string[][] | Record<string, string> | undefined'.
Type 'void' is not assignable to type 'string | URLSearchParams | string[][] | Record<string, string> | undefined'.
We can mitigate this error by adding a return prev after setting the new value but that might not be the expected behaviour.
Am I missing something here ?
joelburget, mfurgala, SantiagoSchez, tomasklaen, mweidner037 and 4 more
Metadata
Metadata
Assignees
Labels
No labels