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

QueryObserver.md

21 lines454 Bytes

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