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.13k stars 95 forks source link

includeAllParams not working #268

Open pdme opened 1 year ago

pdme commented 1 year ago

I'm using this lib together with next-query-params.

I have a QueryParamConfigMap which I pass to useQueryParams(queryParamConfigMap, { includeAllParams: true })

The return value however does not include query params that are not included in the config.

alioguzhan commented 1 year ago

Same here. I both configured this on provider and hook levels but it does not include the params does not exists in the config map.

I am generating some filter inputs based on some remote data. I have no idea about the names and count.

As a workaround, I am building a second param config on the fly and merging it with the existing one:

const ConfigForRemote = remoteData.attributes.reduce((acc, attr) => {
    return { ...acc, [attr.code]: withDefault(StringParam, undefined) };
  }, {} as any);

const [params, setParams] = useQueryParams<typeof MyParamConfig>({ ...MyParamConfig, ...ConfigForRemote });

The above is working so far.