examples/react/playground
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack React 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 }]and passing the querysignalto the API, andtodosQueries.detail(id)withqueryOptions, plustodosMutations.create()andtodosMutations.update()withmutationOptions.src/services/todos/api.tskeeps the todos in memory, responds after a random delay betweenserverConfig.queryTimeMinandserverConfig.queryTimeMax, and rejects at the rate set inserverConfig.errorRate.- In
src/index.tsx, the inputs inRootupdateserverConfigand callqueryClient.setDefaultOptionswith the chosenstaleTimeandgcTime. EachTodoslist runsuseQuery(todosQueries.list(filter))with its own filter and showsfailureCountwhile retrying, and "Force Refetch All" callsqueryClient.invalidateQueries(). EditTodoandAddTodoinsrc/index.tsxrun the mutations withuseMutationand invalidatetodosQueries.lists()on success.EditTodoalso writes the saved todo into its detail query withqueryClient.setQueryData.
To run this example:
npm installnpm run dev