Skip to content

data is undefined when using refetch with enabled=false #8861

@khanakia

Description

@khanakia

Describe the bug

When i refetch with enabled=false data is undefined but the strange thing is when I press backspace it returns the data

'use client';
import { useState } from 'react';
import { useFuncToolsQuery } from '~/generated/aitools/graphql';

export default function DynamicEntitySelect() {
  const [inputValue, setInputValue] = useState('');

  const { data, isFetching, refetch, isLoading } = useFuncToolsQuery(
    {
      first: 100,
      where: {
        ...(inputValue ? { nameContainsFold: inputValue } : {}),
      },
    },
    {
      // enabled: !isBlank(workspaceId),
      enabled: false,
      staleTime: 0,
      // keepPreviousData: true,
    }
  );
  console.log('data', data, isLoading);

  return (
    <>
      <input
        className='border'
        type='text'
        onChange={(e) => {
          setInputValue(e.target.value);
          refetch();
        }}
      />
    </>
  );
}

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-query-ac2kebkt?file=src%2Findex.tsx

Steps to reproduce

  • Copy and paste iphone
  • Now press backspace it still searches for iphone not iphon

Expected behavior

it should search for data

How often does this bug happen?

None

Screenshots or Videos

Screen.Recording.2025-03-27.at.9.09.52.PM.mov

Platform

  • OS: MAc
  • Browser: Chrome
  • Version: "@tanstack/react-query": "^5.67.3"

Tanstack Query adapter

react-query

TanStack Query version

5.67.3

TypeScript version

5.8.2

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