Open History to see the last commit
1---
2id: disabling-queries
3title: Disabling/Pausing Queries
4ref: docs/framework/react/guides/disabling-queries.md
5replace: { 'react-query': 'preact-query', 'React': 'Preact' }
6---
7β
8[//]: # 'Example2'
9β
10```tsx
11function Todos() {
12 const [filter, setFilter] = useState('')
13β
14 const { data } = useQuery({
15 queryKey: ['todos', filter],
16 queryFn: () => fetchTodos(filter),
17 // β¬οΈ disabled as long as the filter is empty
18 enabled: !!filter,
19 })
20β
21 return (
22 <div>
23 // π applying the filter will enable and execute the query
24 <FiltersForm onApply={setFilter} />
25 {data && <TodosTable data={data} />}
26 </div>
27 )
28}
29```
30β
31[//]: # 'Example2'
32[//]: # 'Example3'
33β
34```tsx
35import { skipToken, useQuery } from '@tanstack/preact-query'
36β
37function Todos() {
38 const [filter, setFilter] = useState<string | undefined>()
39β
40 const { data } = useQuery({
41 queryKey: ['todos', filter],
42 // β¬οΈ disabled as long as the filter is undefined or empty
43 queryFn: filter ? () => fetchTodos(filter) : skipToken,
44 })
45β
46 return (
47 <div>
48 // π applying the filter will enable and execute the query
49 <FiltersForm onApply={setFilter} />
50 {data && <TodosTable data={data} />}
51 </div>
52 )
53}
54```
55β
56[//]: # 'Example3'