T
TanStack16mo ago
extended-salmon

React Search Params - Page Index

Hi there, what is the proper way to keep the current page index inside the url? I've tried some things using searchParams and managing the pagination state myself, but it does not seam to work.
2 Replies
deep-jade
deep-jade16mo ago
what's not working about it? I've been using this library https://github.com/47ng/nuqs to make things easier
extended-salmon
extended-salmonOP16mo ago
The issue was, that the inital state value is read from the url, but everytime the state changes, i updated the url using useEffect. I managed to stop an infinite loop (when updating the url, the page reloads, and because of that the state is set, and the url changed, state set, ....) but somehow it always went back to page 0. I checked the code very often, there was no problem there. I will look into the library

Did you find this page helpful?