Closed RomanTokar closed 2 years ago
The issue is you're creating a new param each render by calling withDefault so useQueryParams doesn't know it can keep the old value. If you define your parameter type once, it will work as expected:
const MyParam = withDefault(JsonParam, {})
export default function App() {
const [query, setQuery] = useQueryParams({
json: MyParam
});
...
}
``
@pbeshai Thanks for help and thanks for having such a great package. I guess it would be great if that would be described in the documentation.
Actual behavior
Console
https://codesandbox.io/s/use-query-params-jsonparam-issue-737tn4?file=/src/App.js
As you can see, whenever we call
setQuery
and change our params, a reference toquery.json
is changed and the seconduseEffect
is called.Expected behavior
I assume that it should work the same as behavior of the
useState
hookConsole