pbeshai / use-query-params

React Hook for managing state in URL query parameters with easy serialization.

Home Page:https://pbeshai.github.io/use-query-params

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mistyped urlName in QueryParamConfig

aub opened this issue · comments

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.

oh wow yes you're right! thank you!

should be fixed in serialize-query-params 2.0.1

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.