function useDropAndReplaceUserOperation<TEntryPointVersion, TAccount>(
config,
): UseDropAndReplaceUserOperationResult<TEntryPointVersion, TAccount>;Defined in: account-kit/react/src/hooks/useDropAndReplaceUserOperation.ts:110
Custom hook that handles the drop and replace user operation for a given client and mutation arguments.
import React from "react";
import {
useDropAndReplaceUserOperation,
useSendUserOperation,
useSmartAccountClient,
} from "@account-kit/react";
export function ComponentWithDropAndReplaceUO() {
const { client } = useSmartAccountClient({});
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>
);
}| Type Parameter | Default type |
|---|---|
| ‐ |
|
|
| Parameter | Type | Description |
|---|---|---|
|
| The configuration parameters including the client and other mutation arguments. ref |
UseDropAndReplaceUserOperationResult<TEntryPointVersion, TAccount>
The result containing the mutation function, result data, loading state, and any error. ref