Immediate UI Update Issue in TanStack Table v8 with React Query Deletions #5670
-
When using TanStack Table (v8) with React Query to fetch and display data, the table UI does not immediately update after deleting rows. The deleted rows are removed from the backend, but the changes are not reflected in the UI until a manual refresh or another action triggers a re-render. Compenent fetching and passing data to the table import { Account, columns } from "./columns"; const fetchAccounts = async(): Promise<Account[]>=>{ //fetch data const { onOpen } = useAddNewAccountModal(); if(isLoading) { ); Accounts page Add new <DataTable onDelete={(data)=>{ ); export default AccountsPage; ` delete hook import API import { toast } from "sonner" const deleteUser = async (data: {data: string[]}) => { const useDeleteAccount = () => {
}) export default useDeleteAccount;` i am positive that deletion is done successfully however i have to manually reload to see the changes.Thanks for your help |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Follow the react query optimistic updates examples |
Beta Was this translation helpful? Give feedback.
How are you calling the
setQuerData
? That's what is responsible for the immediate optimistic update. Invalidate queries just causes a new fetch after the fact.