T
TanStack3y ago
eager-peach

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
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?
4 Replies
like-gold
like-gold3y ago
which problem are you trying to solve? It shouldn't be necessary to put data into redux when you get a successful api response
eager-peach
eager-peachOP3y ago
when i get a successful api response i want to process data and store it in redux Is this the wrong approach?
eager-peach
eager-peachOP3y ago
ok i'll read it again thanks!

Did you find this page helpful?