useDropAndReplaceUserOperation
Custom hook that handles the drop and replace user operation for a given client and mutation arguments.
Import
import { useDropAndReplaceUserOperation } from "@account-kit/react";
Usage
import {
useDropAndReplaceUserOperation,
useSendUserOperation,
useSmartAccountClient,
} from "@account-kit/react";
export function ComponentWithDropAndReplaceUO() {
const { client } = useSmartAccountClient({
type: "MultiOwnerModularAccount",
});
const { sendUserOperationAsync, isSendingUserOperation } =
useSendUserOperation({
client,
});
const { dropAndReplaceUserOperation, isDroppingAndReplacingUserOperation } =
useDropAndReplaceUserOperation({
client,
onSuccess: ({ hash, request }) => {
// [optional] Do something with the hash and request
},
onError: (error) => {
// [optional] Do something with the error
},
// [optional] ...additional mutationArgs
});
return (
<div>
<button
onClick={async () => {
const { request } = await sendUserOperationAsync({
uo: {
target: "0xTARGET_ADDRESS",
data: "0x",
value: 0n,
},
});
dropAndReplaceUserOperation({
uoToDrop: request,
});
}}
disabled={isSendingUserOperation || isDroppingAndReplacingUserOperation}
>
{isSendingUserOperation
? "Sending..."
: isDroppingAndReplacingUserOperation
? "Replacing..."
: "Send then Replace UO"}
</button>
</div>
);
}
Parameters
config
UseDropAndReplaceUserOperationArgs<TEntryPointVersion, TAccount>
The configuration parameters including the client and other mutation arguments
Returns
UseDropAndReplaceUserOperationResult<TEntryPointVersion, TAccount>
The result containing the mutation function, result data, loading state, and any error