TanStackT
TanStack15mo ago
4 replies
faint-white

Error Handling with React Query

Wanted to ask something about error handling using React Query. Novice question but wanted to understand the inner working + if I am going right about this.
All the examples I have seen of it being used are something along the lines of

  const { data, isError } = useQuery({
    queryKey: ['something'],
    queryFn: () => fetch(`some-http-url`).then((res) => res.json()),
  });


I have almost never seen React Query functions being wrapped in a try catch or a fetch.then.catch block. They're generally a fetch().then() line of code only.
Am I right in saying you don't need to do that with React query since the isError thing handles Errors for you? Or am I missing something on top of this?
Was this page helpful?