Open History to see the last commit
TanStack Preact 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/queries.tsdefinestodosQueries.list(filter)keyed by['todos', 'list', { filter }]andtodosQueries.detail(id)withqueryOptions, andtodosMutations.create()andtodosMutations.update()withmutationOptions.src/services/todos/api.tsis an in-memory todo server with a random delay and error rate set byserverConfig.getTodosreceives the query'ssignaland logs when a request is cancelled.- In
src/index.tsx,RootcallsqueryClient.setDefaultOptionswhenever thestaleTimeorgcTimeinputs change, and writes the error rate and fetch times intoserverConfig. TodosandEditTodoinsrc/index.tsxcalluseQueryand showfailureCountwhile retrying. Saving or adding a todo withuseMutationinvalidatestodosQueries.lists(), and saving also writes the result withsetQueryData. "Force Refetch All" callsqueryClient.invalidateQueries().
To run this example:
npm installnpm run dev