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

QueryObserver.md

21 lines507 Bytes

1---
2id: QueryObserver
3title: QueryObserver
4redirect_from:
5 - framework/react/reference/QueryObserver
6---
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/functions/useQuery.md).