Open History to see the last commit
1---
2id: quick-start
3title: Quick Start
4---
5β
6Create one `QueryClient` for the browser application, provide it above query
7consumers, and call the Octane hooks from component bodies.
8β
9```tsrx
10import {
11 QueryClient,
12 QueryClientProvider,
13 useMutation,
14 useQuery,
15 useQueryClient,
16} from '@tanstack/octane-query'
17import { addTodo, getTodos } from './api'
18β
19const queryClient = new QueryClient()
20β
21function Todos() @{
22 const client = useQueryClient()
23 const todos = useQuery({
24 queryKey: ['todos'],
25 queryFn: getTodos,
26 })
27 const addTodoMutation = useMutation({
28 mutationFn: addTodo,
29 onSuccess: async () => {
30 await client.invalidateQueries({ queryKey: ['todos'] })
31 },
32 })
33β
34 @if (todos.isPending) {
35 <p>{'Loading...'}</p>
36 } @else if (todos.isError) {
37 <p>{todos.error.message}</p>
38 } @else {
39 <ul>
40 {todos.data.map((todo) => <li>{todo.title}</li>)}
41 </ul>
42 <button
43 disabled={addTodoMutation.isPending}
44 onClick={() => addTodoMutation.mutate({ title: 'Read the Query docs' })}
45 >
46 {'Add todo'}
47 </button>
48 }
49}
50β
51function App() @{
52 <QueryClientProvider client={queryClient}>
53 <Todos />
54 </QueryClientProvider>
55}
56```
57β
58Query option objects, keys, invalidation, retries, caching, and mutations use
59the same TanStack Query contracts as the other framework adapters. The Octane
60adapter changes the rendering and subscription layer, not Query Core.