New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useRouteQuery should support array #3878
Comments
You can check the URL by calling You have two options to achieve what you want:
const toArray = (param: LocationQueryValue | LocationQueryValue[]) =>
Array.isArray(param) ? param : [param];
const type = useRouteQuery('state', [], { transform: toArray });
|
Clear and concise description of the problem
Some times a query param can have multiple values: ?state=NEW&state=OLD
In this case you may want to always get an array if you read the query param, either an empty array or an array with one or more values. Two in the example.
However, what you get is a string if there is only one value, and an array only if there are multiple values. If you use useRouteQuery with
{transform: Array}
you get an array if there is 0 or 1 values, but if there are multiple values you get an array with an array.Suggested solution
Fix so if
{transform: Array}
is used, it always returns a flattened array.Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: