Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions docs/framework/react/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...'
Expand Down
7 changes: 6 additions & 1 deletion examples/react/simple/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ function Example() {
const response = await fetch(
'https://api.github.com/repos/TanStack/query',
)
return await response.json()

if (!response.ok) {
throw new Error(`Request failed with status ${response.status}`)
}

return response.json()
},
})

Expand Down