question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useQuery return always isLoading with true when enabled is false

See original GitHub issue

Describe the bug

When I created useQuery with enabled: false option, isLoading variable is always true.

Your minimal, reproducible example

https://codesandbox.io/s/react-query-enabled-7u58d5-7u58d5

Steps to reproduce

  1. Create simple query by use useQuery,
  2. Add enabled: false into options,
  3. Check state for isLoading.

Expected behavior

State isLoading is false.

How often does this bug happen?

Every time

Screenshots or Videos

image

Platform

  • OS: Windows 11 22H2,
  • Browser: Chrome
  • Version: 103

react-query version

4.0.10

TypeScript version

4.7.4

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:30 (2 by maintainers)

github_iconTop GitHub Comments

23reactions
TkDodocommented, Sep 13, 2022

So I think I have up my mind for what I want to do for the next major version. Believe me, I am terribly sorry that I didn’t do this with v4 already. No one regrets this more than me. The plan is to:

  1. rename status: 'loading' to status: 'pending'
  2. rename isLoading to isPending (a simple derived state from the status, like isSuccess and isError)
  3. re-introduce isLoading as derived value from: isPending && isFetching

That would allow our main status field to remain intact and describe data (pending/success/error), while also having a good isLoading boolean that works like in v3. The breaking thing would be that status === 'loading' wouldn’t exist anymore, as you would have to change it to status === 'pending'.


The thing is, if we introduce something now that combines the two like isInitialDataLoading or whatever, it wouldn’t actually be needed, as it would be isLoading as described above.

With that in mind, yes, I think we can:

  • introduce a new field that combines isLoading && isFetching now.
  • do the proposed changes in v5
  • deprecate the new field that we introduce now in v5 and “alias” it to the then good isLoading
  • remove it in v6.

Please drop more name suggestions, and I’ll also run this proposal by @tannerlinsley

7reactions
angleecommented, Aug 15, 2022

I found this issue after running into the same issue and spending time debugging it. And tbh, I also had the same ‘are you serious?’ thought.

For a breaking change like this, I didn’t find the word ‘enabled’ used in the doc Migrating to React Query 4. It would be helpful to include explicit instructions (e.g. a before&after code example) about how to migrate code with enabled: false in the guide.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Beta] Disabled query has isLoading: true property #3584
Describe the bug In react-query@beta version has strange behaviour. By default query that has enabled: false option has isLoading: true ...
Read more >
What state represents the loading or data not fetched yet state ...
Because I am using the enabled dependency, the isLoading is false and isSuccess is true on the initial page load.
Read more >
useQuery | TanStack Query Docs
enabled : boolean. Set this to false to disable this query from automatically running. Can be used for Dependent Queries. networkMode: 'online' |...
Read more >
Queries - Apollo GraphQL Docs
When your component renders, useQuery returns an object from Apollo Client that contains loading , error , and data properties you can use...
Read more >
Fetching data with React - GQty
This hook returns the core query object, and it will detect the usage of it, and suspend (if enabled) when the data is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found