diff --git a/examples/react/basic-graphql-request/src/index.tsx b/examples/react/basic-graphql-request/src/index.tsx index 9f24de0b48..5da61e93b6 100644 --- a/examples/react/basic-graphql-request/src/index.tsx +++ b/examples/react/basic-graphql-request/src/index.tsx @@ -36,17 +36,13 @@ function App() { ) } -function usePosts() { - return useQuery(postsQueries.list()) -} - function Posts({ setPostId, }: { setPostId: React.Dispatch> }) { const queryClient = useQueryClient() - const { status, data, error, isFetching } = usePosts() + const { status, data, error, isFetching } = useQuery(postsQueries.list()) return (
@@ -90,10 +86,6 @@ function Posts({ ) } -function usePost(postId: string) { - return useQuery(postsQueries.detail(postId)) -} - function Post({ postId, setPostId, @@ -101,7 +93,9 @@ function Post({ postId: string setPostId: React.Dispatch> }) { - const { status, data, error, isFetching } = usePost(postId) + const { status, data, error, isFetching } = useQuery( + postsQueries.detail(postId), + ) return (
diff --git a/examples/react/basic/src/index.tsx b/examples/react/basic/src/index.tsx index b252747019..6dc6b10a21 100644 --- a/examples/react/basic/src/index.tsx +++ b/examples/react/basic/src/index.tsx @@ -18,17 +18,13 @@ const persister = createAsyncStoragePersister({ storage: window.localStorage, }) -function usePosts() { - return useQuery(postsQueries.list()) -} - function Posts({ setPostId, }: { setPostId: React.Dispatch> }) { const queryClient = useQueryClient() - const { status, data, error, isFetching } = usePosts() + const { status, data, error, isFetching } = useQuery(postsQueries.list()) return (
@@ -72,10 +68,6 @@ function Posts({ ) } -function usePost(postId: number) { - return useQuery(postsQueries.detail(postId)) -} - function Post({ postId, setPostId, @@ -83,7 +75,9 @@ function Post({ postId: number setPostId: React.Dispatch> }) { - const { status, data, error, isFetching } = usePost(postId) + const { status, data, error, isFetching } = useQuery( + postsQueries.detail(postId), + ) return (
diff --git a/examples/react/eslint-legacy/src/index.tsx b/examples/react/eslint-legacy/src/index.tsx index 9ddea366c3..062a7fc9ca 100644 --- a/examples/react/eslint-legacy/src/index.tsx +++ b/examples/react/eslint-legacy/src/index.tsx @@ -23,23 +23,19 @@ type Post = { body: string } -function usePosts() { - return useQuery({ - queryKey: ['posts'], - queryFn: async (): Promise> => { - const response = await fetch('https://jsonplaceholder.typicode.com/posts') - return await response.json() - }, - }) -} - function Posts({ setPostId, }: { setPostId: React.Dispatch> }) { const queryClient = useQueryClient() - const { status, data, error, isFetching } = usePosts() + const { status, data, error, isFetching } = useQuery({ + queryKey: ['posts'], + queryFn: async (): Promise> => { + const response = await fetch('https://jsonplaceholder.typicode.com/posts') + return await response.json() + }, + }) return (
@@ -88,14 +84,6 @@ const getPostById = async (id: number): Promise => { return await response.json() } -function usePost(postId: number) { - return useQuery({ - queryKey: ['post', postId], - queryFn: () => getPostById(postId), - enabled: !!postId, - }) -} - function Post({ postId, setPostId, @@ -103,7 +91,11 @@ function Post({ postId: number setPostId: React.Dispatch> }) { - const { status, data, error, isFetching } = usePost(postId) + const { status, data, error, isFetching } = useQuery({ + queryKey: ['post', postId], + queryFn: () => getPostById(postId), + enabled: !!postId, + }) return (
diff --git a/examples/react/nextjs-suspense-streaming/src/app/page.tsx b/examples/react/nextjs-suspense-streaming/src/app/page.tsx index 6a9f117058..d393841208 100644 --- a/examples/react/nextjs-suspense-streaming/src/app/page.tsx +++ b/examples/react/nextjs-suspense-streaming/src/app/page.tsx @@ -14,8 +14,8 @@ function getBaseURL() { return 'http://localhost:3000' } const baseUrl = getBaseURL() -function useWaitQuery(props: { wait: number }) { - const query = useSuspenseQuery({ +function MyComponent(props: { wait: number }) { + const { data } = useSuspenseQuery({ queryKey: ['wait', props.wait], queryFn: async () => { const path = `/api/wait?wait=${props.wait}` @@ -30,12 +30,6 @@ function useWaitQuery(props: { wait: number }) { }, }) - return [query.data, query] as const -} - -function MyComponent(props: { wait: number }) { - const [data] = useWaitQuery(props) - return
result: {data}
} diff --git a/examples/react/nextjs/src/components/PostList.tsx b/examples/react/nextjs/src/components/PostList.tsx index 3327627b84..45f2b8c0d4 100644 --- a/examples/react/nextjs/src/components/PostList.tsx +++ b/examples/react/nextjs/src/components/PostList.tsx @@ -1,9 +1,12 @@ import React, { useState } from 'react' -import { usePosts } from '../hooks/usePosts' +import { useQuery } from '@tanstack/react-query' +import { postsQueries } from '../services/posts/queries' export const PostList = () => { const [postCount, setPostCount] = useState(10) - const { data, error, isPending, isError, isFetching } = usePosts(postCount) + const { data, error, isPending, isError, isFetching } = useQuery( + postsQueries.list(postCount), + ) if (isPending) return
Loading
diff --git a/examples/react/nextjs/src/hooks/usePosts.ts b/examples/react/nextjs/src/hooks/usePosts.ts deleted file mode 100644 index bfac5a0447..0000000000 --- a/examples/react/nextjs/src/hooks/usePosts.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { useQuery } from '@tanstack/react-query' -import { postsQueries } from '../services/posts/queries' - -const usePosts = (limit: number) => { - return useQuery(postsQueries.list(limit)) -} - -export { usePosts }