pbeshai / use-query-params

React Hook for managing state in URL query parameters with easy serialization.
https://pbeshai.github.io/use-query-params
ISC License
2.15k stars 96 forks source link

Mistyped urlName in QueryParamConfig #227

Closed aub closed 2 years ago

aub commented 2 years ago

In here the value passed to urlName for a QueryParamConfig is limited to the types of things that can be decoded for the param, but I think it should be allowed to be any string. With the current typing, this is allowed:

const categoryParam = createEnumParam<JourneyCategoryEnum>(Object.values(JourneyCategoryEnum));
categoryParam.urlName = undefined;
categoryParam.urlName = JourneyCategoryEnum.all;

But this is not allowed:

const categoryParam = createEnumParam<JourneyCategoryEnum>(Object.values(JourneyCategoryEnum));
categoryParam.urlName = 'CATEGORY';

Since we're just specifying what we want to call the param in the URL, shouldn't any string be allowed? I changed the line linked above to:

urlName?: String;

And everything now works as I expected.

pbeshai commented 2 years ago

oh wow yes you're right! thank you!

pbeshai commented 2 years ago

should be fixed in serialize-query-params 2.0.1

aub commented 2 years ago

Nice, thanks for the fix! I had been trying to figure out how to get this functionality myself and kept failing, so I'm really happy to see it supported directly.