Refetch with enabled: false executes request but data is undefined #1273
-
Hello, const { data, refetch, isSuccess } = useQuery(
['alarms', lowerLimitDate, upperLimitDate, selectedSources],
() =>
AlarmExtractionAPI.getAlarms({
dateBegin: lowerLimitDate,
dateEnd: upperLimitDate,
sources: selectedSources
}).then(res => res.data),
{ enabled: false }
); When I execute refetch the request is successfully made, but data is still undefined and isSuccess is false (only isIdle and isStale are set to true) Is this a bug or I am doing something wrong? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hmm, the docs explicitly mention that this should work: So maybe it is a bug. Could you create a reproducible codesandbox that shows that behaviour? As an alternative, instead of triggering But I would still be interested if you can reproduce that bug in codesandbox :) |
Beta Was this translation helpful? Give feedback.
Hmm, the docs explicitly mention that this should work:
https://github.com/tannerlinsley/react-query/blob/25a776d98dfbd629b301abce4dc9b76e5409c881/src/core/types.ts#L72-L77
So maybe it is a bug. Could you create a reproducible codesandbox that shows that behaviour?
As an alternative, instead of triggering
refetch
manually, you could keep astate
boolean variable and pass that toenabled
. Then, when you want to trigger the refetch, just set the boolean to true, which will trigger a re-render and the query will then beenabled
and fetch normally. This is how I've been handling queries that should be disabled until some action is taken.But I would still be interested if you can reproduce th…