How do I clear url query params with a reset button? #994
-
|
I've implemented multiple query params using http://localhost:3000/meetings?statuses=ANALYSIS_READY,ANALYSIS_IN_PROGRESS,ONGOING and when I hit the reset button (clearAllFilters function runs ) the url becomes http://localhost:3000/meetings?statuses=&within=2025-04-06T21:00:00.000Z,2025-05-07T20:59:59.999Z I don't want empty url params to stay in the url. I don't know why my reset function does the fix because clearOnDefault option is set to true. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
If you have persisted filters in localStorage, then the default value is set to that, so setting it to an empty array in the reset function is not going to match the default value, and therefore not clear it from the URL. Instead, you should set the states you want to reset to
The issue with point n°2 is that the default value is closed over from the previous render, and so updating the local storage, even if done before updating the URL state, will still use a stale default value from the previous render. You'd have to:
|
Beta Was this translation helpful? Give feedback.
If you have persisted filters in localStorage, then the default value is set to that, so setting it to an empty array in the reset function is not going to match the default value, and therefore not clear it from the URL.
Instead, you should set the states you want to reset to
null, which will:The issue with point n°2 is that the default value is closed over from the previous render, and so updating the local storage, even if done before updating the URL state, will still use a stale default value from the previous render. You'd have to: