Skip to content
Source
Sign inSign up
TanStack/query

Using state inside `combine` function uses previous value #6648

Send to my agent
Closeddhulme(GitHub profile, opens in a new tab) opened this issue 2 comments

Describe the bug

Using some state within a combine function uses the previous state value, instead of the latest one. Doing a similar approach within a select works as expected.

Your minimal, reproducible example

https://codesandbox.io/p/devbox/elastic-noether-twswhs

Steps to reproduce

On codesandbox link, notice how the data from query2 (using useQueries and combine), lags behind the latest value of the state used in query1 (using useQuery and select).

Expected behavior

combine function should use the latest value of the variable in the closure

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Chrome

Tanstack Query adapter

react-query

TanStack Query version

v5.17.1

TypeScript version

No response

Additional context

No response

  1. TkDodo added labelsbug

  2. TkDodo added labelspackage: react-query

  3. thanks for reporting. I'll look into this - or do you want to?. First "good" news is that it behaves the same in 5.0.0, so it's not a recently introduced regression.

  4. Thank you - sorry I don't think I can look into it

  5. TkDodo closed this

Sign in to join this conversation.