-
|
I have been struggling to get controlled Or maybe I am missing something? const latestPriceQuery = defineQueryOptions(
({
enabled,
symbol = "",
autoRefetch = false,
}: {
enabled: boolean
symbol?: string
autoRefetch?: number | boolean
}) => ({
key: QUERY_KEYS.price(symbol),
query: () => $fetch(`/api/assets/${symbol}/last`),
enabled: !!symbol && enabled,
autoRefetch,
}),
)//doesn't work --- keeps querying even when `state.enabled` becomes false
useQuery(latestCryptoPriceQuery, () => ({
enabled: state.enabled,
symbol: state.symbol,
autoRefetch: state.enabled ? 15000 : false,
}))//doesn't work --- keeps querying even when `state.enabled` becomes false
useQuery(() => latestCryptoPriceQuery({
enabled: state.enabled,
symbol: state.symbol,
autoRefetch: state.enabled ? 15000 : false,
}))//doesn't work --- keeps querying even when `state.enabled` becomes false
useQuery(() => ({...latestCryptoPriceQuery({
enabled: state.enabled,
symbol: state.symbol,
}),
autoRefetch: state.enabled ? 15000 : false,
)//finally works --- fetch pasuses once state.enabled becomes false
useQuery(() => ({...latestCryptoPriceQuery({
enabled: state.enabled,
symbol: state.symbol,
}),
autoRefetch: ()=>state.enabled ? 15000 : false,
)Am I missing something or autoRefetch is not supported as dynamic parameter inside defineQueryOptions Or am I passing dynamic parameters in wrong way? Stack: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
enabled should block the auto refetch. I thought I had unit tests for this 🤔 |
Beta Was this translation helpful? Give feedback.
-
|
also, @posva seems something wrong with my query. It doesn't recognise dynamic parameters, even without autoRefetch. Here state is |
Beta Was this translation helpful? Give feedback.
-
|
Remember to add the language to code fences: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#syntax-highlighting |
Beta Was this translation helpful? Give feedback.
I verified and there are tests for both things, so something else is off. Maybe try creating a PR with a unit test or a boiled down reproduction ( no nuxt)