I have a dashboard app that displays a table. I would like it so that when a user clicks a column to sort, enters a filter, etc. the URL be updated with the current state of the table so that it can be shared, bookmarked, etc.
I have found the useSearchParams() hook but implementing it seems to be causing an infinite re-render loop.
The structure of my app is as follows:
- My component (built with TanStack Table) calls a custom hook (useTableHelper) to set initial state like page number, page size, sorts, filters, etc.
- That output is passed into a custom hook (useQueryHelper) that fetches the data via an API based on passed in state. This uses TanStack Query.
- That data is used to render a table
I have tried to set and update the URL in both the useTableHelper hook and the useQueryHelper hook. Obviously I am doing something wrong. I've looked at the docs, done some tutorials, etc. but can't seem to work this out.
Any help is greatly appreciated.