Closed ryan-ju closed 1 year ago
First, Do not pass function into option variables
.
Second, Your tow options are diffrent. If you convert Option 1
to the following code then will get same result.
const query = useQuery({
queryKey: ["todos", {getData}],
queryFn: ({queryKey}) => {
console.log(
">>> [useQuery.queryFn] data =",
queryKey[1].data,
", getData._version =",
queryKey[1].getData._version,
", getData() =",
queryKey[1].getData()
);
return "don't care";
},
cacheTime: 0,
enabled: data.data !== ""
});
"react-query-kit": "1.4.5"
"@tanstack/react-query": "4.29.19"
Description
When using
createQuery
, if I only pass a function (e.g.,getAccessToken()
that returns the latest token) as variable toqueryFn
, then the resulting query does not refresh when the component refreshes (e.g., due to state change).This problem occurs if the query is initilally
enabled: false
, and later enabled.Example code (sandbox link)
Expected
Code in
Option 1
andOption 2
should give the same result.Actual
Code in
Option 1
gives stale value.Option 2
adds an objectdata
to the variables, and it prints the up-to-date value.