Skip to content

useQuery does not resume fetching when re-enabling with a function for enabled and refetchInterval #8358

Closed
@SMhdAsadi

Description

@SMhdAsadi

Describe the bug

When using useQuery with a dynamic enabled property (passing a function) and refetchInterval, the query correctly stops when enabled returns false. However, when enabled returns true again (for example, when re-focusing a screen or toggling the state), the query does not resume executing the queryFn as expected. Logs confirm that the enabled function is called and returns true, but no further calls to the queryFn are made, and the refetchInterval appears to be ignored after re-enabling.

This behavior is problematic for scenarios such as React Native apps where queries should be disabled on inactive screens and resume when the user navigates back.

Your minimal, reproducible example

https://snack.expo.dev/@smhdasadi/reactqueryenabledrefetchintervalbug

Steps to reproduce

  1. Open project in this Expo Snack link.
  2. Observe the query repeatedly calling queryFn at the defined refetchInterval (2 seconds).
  3. Press the button to toggle enabled to false. The query stops, and no further queryFn executions are logged.
  4. Press the button again to toggle enabled back to true. Logs show that enabled is being called and returns true, but the query does not resume execution.
  5. Observe that no further executions of queryFn are triggered.

Expected behavior

When enabled toggles back to true and refetchInterval is defined:

  • The query should resume execution.
  • The queryFn should be called at the defined refetchInterval.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Android, iOS
  • Platform: React Native

Tanstack Query adapter

react-query

TanStack Query version

v5.61.5

TypeScript version

v5.3.3

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions