Skip to content
Discussion options

You must be logged in to vote

Short answer: throwOnError is a runtime flag. It doesn't change the return type, and the runtime doesn't strictly guarantee it either.

Types: useQuery returns a union discriminated by status, and throwOnError isn't part of that type. It can also be a function ((error, query) => boolean), so TS can't know statically whether an error will throw.

Runtime: the error isn't always thrown. In getHasError (react-query/src/errorBoundaryUtils.ts) the throw only happens when:

result.isError &&
  !errorResetBoundary.isReset() &&
  !result.isFetching &&
  query && (... || shouldThrowError(throwOnError, [result.error, query]))

So right after a QueryErrorResetBoundary / ErrorBoundary reset, your compone…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by axelboc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants