Open History to see the last commit
1---
2id: suspense
3title: Suspense
4---
5β
6Solid Query can also be used with Solid's [Suspense](https://docs.solidjs.com/reference/components/suspense) API's.
7β
8To do that you need to wrap your suspendable component with `Suspense` component provided by Solid
9β
10```tsx
11import { Suspense } from 'solid-js'
12;<Suspense fallback={<LoadingSpinner />}>
13 <SuspendableComponent />
14</Suspense>
15```
16β
17You can use async `suspense` function that is provided by `solid-query`.
18β
19```vue
20<script>
21import { defineComponent } from 'vue'
22import { useQuery } from '@tanstack/solid-query'
23β
24const todoFetcher = async () =>
25 await fetch('https://jsonplaceholder.cypress.io/todos').then((response) =>
26 response.json(),
27 )
28export default defineComponent({
29 name: 'SuspendableComponent',
30 async setup() {
31 const { data, suspense } = useQuery(() => ['todos'], todoFetcher)
32 await suspense()
33β
34 return { data }
35 },
36})
37</script>
38```
39β
40## Fetch-on-render vs Render-as-you-fetch
41β
42Out of the box, Solid Query in `suspense` mode works really well as a **Fetch-on-render** solution with no additional configuration. This means that when your components attempt to mount, they will trigger query fetching and suspend, but only once you have imported them and mounted them. If you want to take it to the next level and implement a **Render-as-you-fetch** model, we recommend implementing [Prefetching](../prefetching) on routing callbacks and/or user interactions events to start loading queries before they are mounted and hopefully even before you start importing or mounting their parent components.