query icon indicating copy to clipboard operation
query copied to clipboard

useErrorBoundary option works in useQueries?

Open luizeboli opened this issue 4 years ago • 7 comments

Discussed in https://github.com/tannerlinsley/react-query/discussions/2355

Originally posted by luizeboli June 8, 2021 Hello guys, I have this hook:

export const useOptions = () => {
  return useQueries([
    {
      queryKey: 'groups',
      queryFn: () => axios({ method: 'GET', url: '/groups' }),
      useErrorBoundary: true,
    },
    {
      queryKey: 'types',
      queryFn: () => axios({ method: 'GET', url: '/types' }),
      useErrorBoundary: true,
    },
    {
      queryKey: 'sourcedTypes',
      queryFn: () => axios({ method: 'GET', url: '/sourcedTypes' }),
      useErrorBoundary: true,
    },
  ])
}

The component that consumes this hook is wrapped by a ErrorBoundary, but it doesn't throw while using useQueries. It just works with useQuery.

The only change needed to work correctly is replace useQueries by useQuery.

Is this an expected behavior? I didn't find it in docs

luizeboli avatar Jun 22 '21 19:06 luizeboli

I have the same problem but it does not work yet: https://github.com/tannerlinsley/react-query/pull/2109

RichardLindhout avatar Jun 23 '21 12:06 RichardLindhout

Related: https://github.com/tannerlinsley/react-query/issues/1523

RichardLindhout avatar Jun 23 '21 16:06 RichardLindhout

does useErrorBoundary work in useQueries without suspense? Also, if you open an issue, please create a codesandbox example that reproduces the issue, thanks.

TkDodo avatar Jun 25 '21 17:06 TkDodo

does useErrorBoundary work in useQueries without suspense? Also, if you open an issue, please create a codesandbox example that reproduces the issue, thanks.

It works in useQuery without suspense so maybe its supposed to.

I'm not trying to report a bug its just a question, thats why I did not created a Sandbox. I asked in discussions but got no replies

luizeboli avatar Jun 26 '21 00:06 luizeboli

It works in useQuery without suspense so maybe its supposed to.

That wasn’t the question though. Does it work in useQueries without suspense? Trying to narrow down if it’s useQueries+suspense related, because for that we already have an issue and yes, that doesn’t work yet

TkDodo avatar Jun 26 '21 06:06 TkDodo

Yes useQueries works perfectly without suspense! I only missed an option for refetchInterval in useQueries

RichardLindhout avatar Jun 26 '21 09:06 RichardLindhout

okay, I've made a reproduction: https://codesandbox.io/s/holy-darkness-qy5tw?file=/src/index.js

even with suspense: false, useQueries does not correctly work with useErrorBoundary.

However, I think that the open PR that tries to solve #1523 will also fix this issue, see:

https://github.com/tannerlinsley/react-query/pull/2109/files#diff-d1b1d4e3c1d5b653533620a0b77d0873a170c747a9bd5ae5db7d58f8606262d0R59

If I try out the above reproduction with that PR preview build, it seems to work: https://codesandbox.io/s/tannerlinsleyreact-query-basic-forked-vi4gt

TkDodo avatar Jun 26 '21 10:06 TkDodo