T
TanStack•3y ago
wise-white

Optimistic Update with React Query

Hi! I'm using React Query and React Table in the Next.js app and was wondering if there are examples of optimistic update to the table when sending mutation queries? e.g. each row has a toggle favorite button and I'd like to update the table data on mutation succcess.
3 Replies
flat-fuchsia
flat-fuchsia•3y ago
@injey also looking for this. Did you find any solution?
wise-white
wise-whiteOP•3y ago
Not yet, I put it off to work on something else waiting for a reply 😂
flat-fuchsia
flat-fuchsia•3y ago
@injey yeah so I am using next 13 with the pattern of loading data on server and pasisng it to the tanstack table client component. There I have a use effect hook that runs every time the "server data" that get's passed in as prop changes. When I delete or create an object, I call inside the cell table.options.meta?.routerRefresh() and the server refetches data, passing new server data which should call useEffect and then update the UI. It's not super smoothly working yet, but I am getting somewhere...

Did you find this page helpful?