T
TanStack10mo ago
correct-apricot

onSuccess is not working in component file but working in query file

const addUsers = useAddUsers(); addUsers .mutate( { ids: payload.list, users: payload.users, }, { onSuccess: (data) => { alert('on SUccess'); handleSuccess(data); onSuccessClearStatesAndClose(); }, }, ); onSuccess is not working here const addUsers = (payload: IAddPayload): Promise<IAddResponse> => { const method = 'POST'; const url = ${BASE_URL}.bulk_add_users; return api<IBulkUpdateResponse>({ method, url, body: payload }); }; export const useBulkAddUsers = (): UseMutationResult< IAddResponse, IServerError, IAddPayload
=> {
const queryClient = useQueryClient(); const { toastError, toastSuccess } = useToast(); return useMutation<IAddResponse, IServerError, IAddPayload>({ mutationFn: addUsers , onSuccess: async (data) => { await queryClient.invalidateQueries({ queryKey: assignmentQueryKeys.all }); toastSuccess(data as unknown as string); }, onError: (error: IServerError) => { toastError(handleServerError(error)); }, }); }; the onSuccess is working in query file but its not working in Component file where we do mutate
5 Replies
eager-peach
eager-peach10mo ago
Hello, would you mind using syntax color please ? It's hard to read ```ts // your code here ``` also useAddUsers code isn't there, and I think it's not related to #start-questions but rather #react-query-questions no ?
correct-apricot
correct-apricotOP10mo ago
HI this is my code in component file
No description
eager-peach
eager-peach10mo ago
screenshots aren't ideal either because I can't copy paste and try stuff, you should learn about markdown code block in the future if possible.
genetic-orange
genetic-orange10mo ago
Please make a reproduction in stackblitz and post this in #react-query-questions
eager-peach
eager-peach10mo ago
yeah the code is not quite minimal, if it were we could easily reply without even repro, but there's many things going on here

Did you find this page helpful?