T
TanStack3y ago
generous-apricot

How to perform dom operations after query is updated

I am using react query to display paginated data in a table. When the user clicks on the next "button", I am updating the query key with the new pagination info, trigerring a new fetch. When that fetch succeeds, I would love to scroll to the beginning of the table. Should I use the onSettled prop to achieve this behavior ? However my problem with onSettled is that I would like to avoid performing the change on the initial page load.
3 Replies
adverse-sapphire
adverse-sapphire3y ago
You can use whichever of the callbacks you deem to be most suitable (probably onSuccess I'd imagine). Scrolling to the top of an element that's already scrolled to the top shouldn't matter/make a difference but you could look at the data returned by the query and see if that contains anything that you could use to bail out of performing the scroll but I don't think I'd worry about it.
generous-apricot
generous-apricotOP3y ago
Thx !
adverse-sapphire
adverse-sapphire3y ago
No worries! Let us know if you get stuck :reactquery:

Did you find this page helpful?