1
const myRequest = (req: ReqMyParam) => { return postFetchData<ResMyParam, ReqMyParam>( myRoutes.myApi, req, ) } export const useMyApiMutation = ( onSuccess: (res: ResSuccessMessage<ResMyParam>) => void, onError: (error: ResErrorMessage) => void, ) => { return useMutation({ mutationFn: (req: ReqMyParam) => { return myRequest(req) }, onSuccess: onSuccess, onError: onError, }) } 

This is the source code for useMutation that I wrote.

myRequest( { orderId: DATA.trxUnqNo, totAmt: trxAmt, }, {// How can I add that part to myRequest? rpsCd, rpsMsg, trxSno, }, ) const { mutate: myRequest} = useMyApiMutation( ({ DATA }: ResSuccessMessage<ResMyParam>) => { const url = DATA.checkoutPage otherMutation({ // This is to use additional parameters when calling other APIs. rpsCd: rpsCd, rpsMsg: rpsMsg, trxSno: trxSno, trxUnqNo: '', trxUnqKey: DATA.payToken, }) }, ({ MESSAGE }: ResErrorMessage) => { alert(MESSAGE) }, ) 

The reason why I want to use it like this is because I want to change the then syntax using promise that I was using to mutation.

I'm still unfamiliar with how to use it, so even though I've searched a lot, it doesn't seem to work the way I'm trying. I'm wondering if I'm doing something wrong or if it's impossible.

1
  • 3
    React doesn't have a useMutation hook. It looks like you're using tanstack query. Commented Aug 4, 2024 at 14:44

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.