TanStackT
TanStack4y ago
1 reply
rubber-blue

onSuccess (callback) only on initial load

I would like to define a callback when the data is loaded for the first time. For example, after loading the data I want to display some feedback message. I don't want to display it every time the data is fetched, only for the first time.

Something like this doesn't work, as it is called after every fetch:

  const {
    data,
  } = useQuery(['list'], fetchList, {
    onError: (e) => {
      dispatch(showErrorFeedbackMessage(errorMessage));
    },
    // Do that only after first load
    onSuccess: () => {
      dispatch(showErrorFeedbackMessage(errorMessage));
    }
  });
Was this page helpful?