Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

QueryObserver.md

19 lines438 Bytes

1---
2id: QueryObserver
3title: QueryObserver
4---
5​
6The `QueryObserver` can be used to observe and switch between queries.
7​
8```tsx
9const observer = new QueryObserver(queryClient, { queryKey: ['posts'] })
10​
11const unsubscribe = observer.subscribe((result) => {
12 console.log(result)
13 unsubscribe()
14})
15```
16​
17**Options**
18​
19The options for the `QueryObserver` are exactly the same as those of [`useQuery`](../../framework/react/reference/useQuery).