Skip to content

Commit 5f9eaef

Browse files
authored
chore(solid-query): update examples, integration, docs (#8941)
* chore(solid-query): update examples/intergration * update docs
1 parent 3294054 commit 5f9eaef

File tree

13 files changed

+60
-60
lines changed

13 files changed

+60
-60
lines changed

docs/config.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,8 @@
757757
"label": "solid",
758758
"children": [
759759
{
760-
"label": "createQuery",
761-
"to": "framework/solid/reference/createQuery"
760+
"label": "useQuery",
761+
"to": "framework/solid/reference/useQuery"
762762
}
763763
]
764764
},

docs/framework/solid/reference/createQuery.md renamed to docs/framework/solid/reference/useQuery.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
id: createQuery
3-
title: createQuery
2+
id: useQuery
3+
title: useQuery
44
---
55

66
```tsx
@@ -28,7 +28,7 @@ const {
2828
isSuccess,
2929
refetch,
3030
status,
31-
} = createQuery(
31+
} = useQuery(
3232
() => ({
3333
queryKey,
3434
queryFn,
@@ -60,17 +60,17 @@ const {
6060

6161
## Usage example
6262

63-
Here are some examples of how to use the `createQuery` primitive in Solid Query.
63+
Here are some examples of how to use the `useQuery` primitive in Solid Query.
6464

6565
### Basic
6666

67-
The most basic usage of `createQuery` is to create a query that fetches data from an API.
67+
The most basic usage of `useQuery` is to create a query that fetches data from an API.
6868

6969
```tsx
70-
import { createQuery } from '@tanstack/solid-query'
70+
import { useQuery } from '@tanstack/solid-query'
7171

7272
function App() {
73-
const todos = createQuery(() => ({
73+
const todos = useQuery(() => ({
7474
queryKey: 'todos',
7575
queryFn: async () => {
7676
const response = await fetch('/api/todos')
@@ -104,15 +104,15 @@ function App() {
104104

105105
### Reactive Options
106106

107-
The reason why `createQuery` accepts a function that returns an object is to allow for reactive options. This is useful when query options depend on other values/signals that might change over time. Solid Query can track the passed function in a reactive scope and re-run it whenever the dependencies change.
107+
The reason why `useQuery` accepts a function that returns an object is to allow for reactive options. This is useful when query options depend on other values/signals that might change over time. Solid Query can track the passed function in a reactive scope and re-run it whenever the dependencies change.
108108

109109
```tsx
110-
import { createQuery } from '@tanstack/solid-query'
110+
import { useQuery } from '@tanstack/solid-query'
111111

112112
function App() {
113113
const [filter, setFilter] = createSignal('all')
114114

115-
const todos = createQuery(() => ({
115+
const todos = useQuery(() => ({
116116
queryKey: ['todos', filter()],
117117
queryFn: async () => {
118118
const response = await fetch(`/api/todos?filter=${filter()}`)
@@ -151,13 +151,13 @@ function App() {
151151

152152
### Usage with `Suspense`
153153

154-
`createQuery` supports triggering SolidJS `Suspense` and `ErrorBoundary` components when the query is in a pending or error state. This allows you to easily handle loading and error states in your components.
154+
`useQuery` supports triggering SolidJS `Suspense` and `ErrorBoundary` components when the query is in a pending or error state. This allows you to easily handle loading and error states in your components.
155155

156156
```tsx
157-
import { createQuery } from '@tanstack/solid-query'
157+
import { useQuery } from '@tanstack/solid-query'
158158

159159
function App() {
160-
const todos = createQuery(() => ({
160+
const todos = useQuery(() => ({
161161
queryKey: 'todos',
162162
queryFn: async () => {
163163
const response = await fetch('/api/todos')
@@ -184,7 +184,7 @@ function App() {
184184
}
185185
```
186186

187-
## `createQuery` Parameters
187+
## `useQuery` Parameters
188188

189189
- ### Query Options - `Accessor<QueryOptions>`
190190

@@ -298,9 +298,9 @@ function App() {
298298
- Optional
299299
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
300300

301-
## `createQuery` Return Value - `Store<QueryResult<TData, TError>>`
301+
## `useQuery` Return Value - `Store<QueryResult<TData, TError>>`
302302

303-
`createQuery` returns a SolidJS store with the following properties:
303+
`useQuery` returns a SolidJS store with the following properties:
304304

305305
- ##### `status: QueryStatus`
306306
- Will be:

examples/solid/astro/src/components/SolidApp.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
QueryClient,
33
QueryClientProvider,
4-
createQuery,
54
keepPreviousData,
5+
useQuery,
66
} from '@tanstack/solid-query'
77
import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
88
import {
@@ -13,9 +13,9 @@ import {
1313
createSignal,
1414
useContext,
1515
} from 'solid-js'
16-
import { Link } from './Link'
17-
import { getSearchParams, properCase } from '../utils'
1816
import { isServer } from 'solid-js/web'
17+
import { getSearchParams, properCase } from '../utils'
18+
import { Link } from './Link'
1919

2020
const PokemonIdContext = createContext<() => string>()
2121

@@ -72,7 +72,7 @@ const PokemonDetails = () => {
7272
}
7373

7474
const PokemonDex = (props: { id: string }) => {
75-
const pokemon = createQuery(() => ({
75+
const pokemon = useQuery(() => ({
7676
queryKey: ['pokemon', props.id],
7777
queryFn: async () => {
7878
const res = await fetch(
@@ -83,7 +83,7 @@ const PokemonDex = (props: { id: string }) => {
8383
placeholderData: keepPreviousData,
8484
}))
8585

86-
const pokemon_stats = createQuery(() => ({
86+
const pokemon_stats = useQuery(() => ({
8787
queryKey: ['pokemon', props.id],
8888
queryFn: async () => {
8989
const res = await fetch(
@@ -111,7 +111,7 @@ const PokemonDex = (props: { id: string }) => {
111111
reconcile: 'name',
112112
}))
113113

114-
const is_server_rendered = createQuery(() => ({
114+
const is_server_rendered = useQuery(() => ({
115115
queryKey: ['is_server_rendered', props.id],
116116
queryFn: () => {
117117
if (isServer) return true
@@ -191,7 +191,7 @@ const PokemonDex = (props: { id: string }) => {
191191
const SideNav = () => {
192192
const id = usePokemonID()
193193

194-
const pokemonsList = createQuery(() => ({
194+
const pokemonsList = useQuery(() => ({
195195
queryKey: ['pokemons'],
196196
queryFn: async () => {
197197
const res = await fetch(

examples/solid/basic-graphql-request/src/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {
33
QueryClient,
44
QueryClientProvider,
5-
createQuery,
5+
useQuery,
66
} from '@tanstack/solid-query'
77
import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
88
import { For, Match, Switch, createSignal } from 'solid-js'
@@ -46,7 +46,7 @@ function App() {
4646
}
4747

4848
function createPosts() {
49-
return createQuery(() => ({
49+
return useQuery(() => ({
5050
queryKey: ['posts'],
5151
queryFn: async () => {
5252
const {
@@ -117,7 +117,7 @@ function Posts(props: { setPostId: Setter<number> }) {
117117
}
118118

119119
function createPost(postId: Accessor<number>) {
120-
return createQuery(() => ({
120+
return useQuery(() => ({
121121
queryKey: ['post', postId()],
122122
queryFn: async () => {
123123
const { post } = await request<{ post: Post }>(

examples/solid/basic/src/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {
33
QueryClient,
44
QueryClientProvider,
5-
createQuery,
5+
useQuery,
66
} from '@tanstack/solid-query'
77
import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
88
import { For, Match, Switch, createSignal } from 'solid-js'
@@ -24,7 +24,7 @@ type Post = {
2424
}
2525

2626
function createPosts() {
27-
return createQuery(() => ({
27+
return useQuery(() => ({
2828
queryKey: ['posts'],
2929
queryFn: async (): Promise<Array<Post>> => {
3030
const response = await fetch('https://jsonplaceholder.typicode.com/posts')
@@ -88,7 +88,7 @@ const getPostById = async (id: number): Promise<Post> => {
8888
}
8989

9090
function createPost(postId: number) {
91-
return createQuery(() => ({
91+
return useQuery(() => ({
9292
queryKey: ['post', postId],
9393
queryFn: () => getPostById(postId),
9494
enabled: !!postId,

examples/solid/default-query-function/src/index.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/* @refresh reload */
2-
import type { QueryFunction } from '@tanstack/solid-query'
32
import {
4-
createQuery,
53
QueryClient,
64
QueryClientProvider,
5+
useQuery,
76
} from '@tanstack/solid-query'
87
import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
9-
import type { Setter } from 'solid-js'
10-
import { createSignal, For, Match, Show, Switch } from 'solid-js'
8+
import { For, Match, Show, Switch, createSignal } from 'solid-js'
119
import { render } from 'solid-js/web'
10+
import type { Setter } from 'solid-js'
11+
import type { QueryFunction } from '@tanstack/solid-query'
1212

1313
// Define a default query function that will receive the query key
1414
const defaultQueryFn: QueryFunction<unknown> = async ({ queryKey }) => {
@@ -55,7 +55,7 @@ function App() {
5555

5656
function Posts(props: { setPostId: Setter<number> }) {
5757
// All you have to do now is pass a key!
58-
const state = createQuery<any[]>(() => ({ queryKey: ['/posts'] }))
58+
const state = useQuery<any[]>(() => ({ queryKey: ['/posts'] }))
5959

6060
return (
6161
<div>
@@ -103,7 +103,7 @@ function Posts(props: { setPostId: Setter<number> }) {
103103

104104
function Post(props: { postId: number; setPostId: Setter<number> }) {
105105
// You can even leave out the queryFn and just go straight into options
106-
const state = createQuery<any>(() => ({
106+
const state = useQuery<any>(() => ({
107107
queryKey: [`/posts/${props.postId}`],
108108
enabled: !!props.postId,
109109
}))

examples/solid/simple/src/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {
33
QueryClient,
44
QueryClientProvider,
5-
createQuery,
5+
useQuery,
66
} from '@tanstack/solid-query'
77
import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
88
import { Match, Switch } from 'solid-js'
@@ -20,7 +20,7 @@ export default function App() {
2020
}
2121

2222
function Example() {
23-
const state = createQuery(() => ({
23+
const state = useQuery(() => ({
2424
queryKey: ['repoData'],
2525
queryFn: async () => {
2626
const response = await fetch(

examples/solid/solid-start-streaming/src/components/post-viewer.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { createQuery } from '@tanstack/solid-query'
2-
import type { Component } from 'solid-js'
1+
import { useQuery } from '@tanstack/solid-query'
32
import { resetErrorBoundaries } from 'solid-js'
43
import { createSignal } from 'solid-js'
54
import { For } from 'solid-js'
6-
import { fetchPost } from '~/utils/api'
75
import { Example } from './example'
86
import { QueryBoundary } from './query-boundary'
7+
import type { Component } from 'solid-js'
8+
import { fetchPost } from '~/utils/api'
99

1010
export interface PostViewerProps {
1111
deferStream?: boolean
@@ -17,7 +17,7 @@ export const PostViewer: Component<PostViewerProps> = (props) => {
1717
const [simulateError, setSimulateError] = createSignal(props.simulateError)
1818
const [postId, setPostId] = createSignal(1)
1919

20-
const query = createQuery(() => ({
20+
const query = useQuery(() => ({
2121
queryKey: ['posts', postId()],
2222
queryFn: () =>
2323
fetchPost({

examples/solid/solid-start-streaming/src/components/query-boundary.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { CreateQueryResult } from '@tanstack/solid-query'
2-
import type { JSX } from 'solid-js'
31
import { ErrorBoundary, Match, Suspense, Switch, children } from 'solid-js'
2+
import type { UseQueryResult } from '@tanstack/solid-query'
3+
import type { JSX } from 'solid-js'
44

55
export interface QueryBoundaryProps<T = unknown> {
6-
query: CreateQueryResult<T, Error>
6+
query: UseQueryResult<T, Error>
77

88
/**
99
* Triggered when the data is initially loading.

examples/solid/solid-start-streaming/src/components/user-info.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { createQuery } from '@tanstack/solid-query'
2-
import type { Component } from 'solid-js'
1+
import { useQuery } from '@tanstack/solid-query'
32
import { createSignal } from 'solid-js'
4-
import { fetchUser } from '~/utils/api'
53
import { Example } from './example'
64
import { QueryBoundary } from './query-boundary'
5+
import type { Component } from 'solid-js'
6+
import { fetchUser } from '~/utils/api'
77

88
export interface UserInfoProps {
99
deferStream?: boolean
@@ -25,7 +25,7 @@ export const userInfoQueryOpts = (props?: UserInfoProps) => ({
2525
export const UserInfo: Component<UserInfoProps> = (props) => {
2626
const [simulateError, setSimulateError] = createSignal(props.simulateError)
2727

28-
const query = createQuery(() =>
28+
const query = useQuery(() =>
2929
userInfoQueryOpts({ ...props, simulateError: simulateError() }),
3030
)
3131

examples/solid/solid-start-streaming/src/routes/batch-methods.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createQuery, notifyManager } from '@tanstack/solid-query'
1+
import { notifyManager, useQuery } from '@tanstack/solid-query'
22
import { createSignal } from 'solid-js'
33
import { QueryBoundary } from '~/components/query-boundary'
44

@@ -30,7 +30,7 @@ async function sayHello(name: string) {
3030
export default function BatchMethods() {
3131
const [count, setCount] = createSignal(0)
3232

33-
const hello = createQuery(() => ({
33+
const hello = useQuery(() => ({
3434
queryKey: ['hello', count()] as const,
3535
queryFn: ({ queryKey: [_, count] }) => sayHello(`solid ${count}`),
3636
}))

examples/solid/solid-start-streaming/src/routes/hydration.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type { CreateQueryResult } from '@tanstack/solid-query'
2-
import { createQuery } from '@tanstack/solid-query'
3-
import { createSignal, Suspense } from 'solid-js'
4-
import { fetchUser } from '~/utils/api'
1+
import { useQuery } from '@tanstack/solid-query'
2+
import { Suspense, createSignal } from 'solid-js'
53
import { NoHydration } from 'solid-js/web'
64
import { Title } from '@solidjs/meta'
5+
import type { UseQueryResult } from '@tanstack/solid-query'
6+
import { fetchUser } from '~/utils/api'
77

88
export default function Hydration() {
9-
const query = createQuery(() => ({
9+
const query = useQuery(() => ({
1010
queryKey: ['user'],
1111
queryFn: () => fetchUser({ sleep: 500 }),
1212
deferStream: true,
@@ -69,7 +69,7 @@ export default function Hydration() {
6969
)
7070
}
7171

72-
type QueryState = CreateQueryResult<
72+
type QueryState = UseQueryResult<
7373
{
7474
id: string
7575
name: string

integrations/solid-vite/src/App.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Match, Switch } from 'solid-js'
2-
import { createQuery } from '@tanstack/solid-query'
2+
import { useQuery } from '@tanstack/solid-query'
33

44
const App = () => {
5-
const query = createQuery(() => ({
5+
const query = useQuery(() => ({
66
queryKey: ['test'],
77
queryFn: async () => {
88
await new Promise((r) => setTimeout(r, 1000))

0 commit comments

Comments
 (0)