TanStackT
TanStack3y ago
5 replies
awake-maroon

how to update query data without useEffect

Hi I'm using Redux and React-Query

and i want update response data when api call succeed

when i use onSuccess call back it's work but i read onSuccess is not good so i try

export const useGetListQuery = (data: ReqType): UseQueryResult<HTTPResponse<ResType>> => {
  return useQuery(
    KEY.QUERY(data),
    async () => {
      const { centerId, recipientId, query } = data;
      const result = await api.getList({ centerId, recipientId, query });
      if ('errorCode' in result) {
        return result;
      } else {
        return result.data;
      }
    },
    {
      enabled: !!data.centerId && !!data.recipientId,
    },
  );
};

  const { data: list } = useGetListQuery({
    centerId: blabla,
    recipientId: blabla,
    query: {
      queryData : blabla,
      queryData : blabla,
    },
  });

list ? dispatch(actionFn(payload)) : undefined


and stuck in an endless loop

i don't wan't use useEffect so what should i do?

shuld i use query-key? or cache?
Was this page helpful?