Closed MichaelHefetz closed 1 year ago
You should be able to accomplish this with the objectToSearchParams
option (set at the provider)
Here's an example using query-string, but you can do whatever you like
import { parse, stringify } from 'query-string'
import {
QueryParamOptions,
QueryParamProvider,
transformSearchStringJsonSafe,
} from 'use-query-params'
const useQueryParamsOptions: QueryParamOptions = {
objectToSearchString: (obj) => {
const searchString = stringify(obj)
// add {}[],": back
const jsonSafe = transformSearchStringJsonSafe(searchString)
// add dollar signs back
const result = jsonSafe.replace(/%24/g, '$')
return result
},
searchStringToObject: parse,
}
...
<QueryParamProvider options={useQueryParamsOptions} ...>
The provided helper from this package transformSearchStringJsonSafe
allows {}[],":
in URL query params.
Note if you're not using query-string, you can use the default objectToSearchString
exported from the package instead of stringify
Thank you, will try!
update: it works, thank you
Is it possible to update Url with the original value and not the encoded one?
For example 'a:2:c' not to be encoded as a%3A2%3Ac when updated in Url
We need to use filters in rison format instead of json in Url like Kibana does
so I tried to create custom param.
rison.encode(any) returns decoded value, but in Url we get encoded string with %