From 0203f84311b9ce2517f0b0409f6e0a08b276ca66 Mon Sep 17 00:00:00 2001 From: 0Jaemin0 Date: Tue, 19 May 2026 15:59:40 +0900 Subject: [PATCH 1/2] docs(react): handle failed fetch responses in simple example --- docs/framework/react/overview.md | 15 +++++++++++---- examples/react/simple/src/index.tsx | 5 +++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/framework/react/overview.md b/docs/framework/react/overview.md index 6c9a3f0dacd..aeb41171797 100644 --- a/docs/framework/react/overview.md +++ b/docs/framework/react/overview.md @@ -68,10 +68,17 @@ export default function App() { function Example() { const { isPending, error, data } = useQuery({ queryKey: ['repoData'], - queryFn: () => - fetch('https://api.github.com/repos/TanStack/query').then((res) => - res.json(), - ), + queryFn: async () => { + const response = await fetch( + 'https://api.github.com/repos/TanStack/query', + ) + + if (!response.ok) { + throw new Error(`Request failed with status ${response.status}`) + } + + return response.json() + }, }) if (isPending) return 'Loading...' diff --git a/examples/react/simple/src/index.tsx b/examples/react/simple/src/index.tsx index ba0332f5e6d..39395e3c6b2 100644 --- a/examples/react/simple/src/index.tsx +++ b/examples/react/simple/src/index.tsx @@ -25,6 +25,11 @@ function Example() { const response = await fetch( 'https://api.github.com/repos/TanStack/query', ) + + if (!response.ok) { + throw new Error(`Request failed with status ${response.status}`) + } + return await response.json() }, }) From cee62d0a1f794ee782dd804fb5c20f7158a9462f Mon Sep 17 00:00:00 2001 From: 0Jaemin0 Date: Tue, 19 May 2026 16:15:17 +0900 Subject: [PATCH 2/2] docs(react): align simple example response parsing --- examples/react/simple/src/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/react/simple/src/index.tsx b/examples/react/simple/src/index.tsx index 39395e3c6b2..359393e1ffb 100644 --- a/examples/react/simple/src/index.tsx +++ b/examples/react/simple/src/index.tsx @@ -30,7 +30,7 @@ function Example() { throw new Error(`Request failed with status ${response.status}`) } - return await response.json() + return response.json() }, })