Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useQuery hook sets loaded prop to false when throws error #6233

Closed
paulo9mv opened this issue May 2, 2021 · 1 comment · Fixed by #6252
Closed

useQuery hook sets loaded prop to false when throws error #6233

paulo9mv opened this issue May 2, 2021 · 1 comment · Fixed by #6252
Assignees

Comments

@paulo9mv
Copy link
Contributor

paulo9mv commented May 2, 2021

What you were expecting:

When useQuery() throws an error, i'm expecting loaded to be true, according to the docs:
error: { error: [error from response], loading: false, loaded: true }

What happened instead:

loaded is false after throwed error.

Steps to reproduce:

In simple demo, call useQuery() hook in a way that it throw an error. It will set loaded to false.

Related code:

https://github.com/marmelab/react-admin/blob/9a2fc59fb81b3e2e014eeecc194babb340ff833e/packages/ra-core/src/dataProvider/useQuery.ts

// useQuery.ts
.catch(error => {
                setState({
                    error,
                    loading: false,
                    loaded: false,  // <--- this line seems wrong
                    refetch,
                });
            });
@fzaninotto
Copy link
Member

The problem lies in the documentation, not in the code. useQuery (and other query hooks) should return loaded: false in case of error, because the data isn't loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants