TanStackT
TanStack3y ago
2 replies
moderate-tomato

Removing `onSuccess` from this query

Hi, I have a task endpoint that requires short polling in order to get the response. I recall that onSuccess is a bit of an antipattern with useQuery. How could I remove it in this instance (using v3 RQ)? Thanks

const data = useFetchTaskOutput(taskId, {
    enabled: !outputHasCompleted,
    refetchInterval: 1000,
    retry: false,
    onSuccess: (data) => {
      const completed = Boolean(data.status === 'complete');
      setOutputHasCompleted(completed);
      if (completed) {
        // controlled input handler
        onCompleted(data.value);
      }
    },
  });
Was this page helpful?