Search code examples
redux-toolkitrtk-query

How to use RTK Query with ErrorBoundary


Are there some examples of use with ErrorBoundary?

This is what i can think of:

const { isError: isGetAError, error: getAError } = useGetAQuery()
if (isGetAError) {
  throw getAError
}
const { isError: isGetBError, error: getBError } = useGetBQuery()
if (isGetBError) {
  throw getBError
}

Solution

  • That would probably be the way to do it, or you create your own throwingHooks module with your own way of writing hooks - these are pluggable modules.

    Here is the code to the /query/react module: https://github.com/reduxjs/redux-toolkit/tree/master/packages/toolkit/src/query/react