Open History to see the last commit
TanStack Vue Query Playground Example#
A todo list with adjustable staleTime, gcTime and error rate, to see how queries and mutations react to them.
How it works#
src/services/todos/api.tsis an in-memory todo server. Each call waits a random time and fails at a random rate, both read from the exportedserverConfig.src/services/todos/queries.tsdefinestodosQueries.list(filter)andtodosQueries.detail(id)withqueryOptions, andtodosMutations.create()andtodosMutations.update()withmutationOptions. The list query passes itssignalto the API.src/TodoList.vuepasses a getter touseQuerythat follows the filter input, and showsfailureCount + 1as the attempt number while loading or refetching.src/App.vuerenders several of these lists at once.src/AddTodo.vueandsrc/EditTodo.vuecalluseMutation. On success both invalidatetodosQueries.lists(), andsrc/EditTodo.vuealso writes the saved todo withqueryClient.setQueryData.src/App.vueapplies thestaleTimeandgcTimeinputs withqueryClient.setDefaultOptionsinsidewatchEffect, copies the error rate and fetch times intoserverConfig, and refetches everything withqueryClient.invalidateQueries().
To run this example:
npm installnpm run dev