Facing issues with onSuccess and onComplete - What is it used for?

I’ve been trying to call two transactions - Second one only after the first transaction is “CONFIRMED”. I tried to use onSuccess and onComplete, but both fires immediately after the transaction is “SENT” and does not wait for the first transaction to get confirmed. Since my second transaction depends on the first one, I was never able to successfully complete both the transactions. I also don’t understand the difference between them as both seems to function in the same way.

I’ve stuck for 3 days in a row. I went through the forum for related queries but did not find anything useful or it does not work. Any solution would be helpful for me.

What are you using? React, vanilla js, what function?

You can also use web3 or ethers directly

I’m using ‘react-moralis’ module. (useWeb3Contract hook)

runContractFunction({
            params: {...},
            onSuccess: (results) => {...print the result...and then execute the next runContractFunction..},
            onError: (error) => {..print the error..}
})

Yeah, I could use Web3 directly, but then in which scenario should I use onSuccess and onComplete?