use approve
const { approve, approveMax, isPending, isSuccess } = useApprove({ token })Usage
import { useApprove } from '@yo-protocol/react'
import { parseEther } from 'viem'
function ApproveButton({ token }: { token: `0x${string}` }) {
const {
approve,
approveMax,
isPending,
isSuccess,
hash,
error,
reset,
} = useApprove({
token,
onSubmitted: (hash) => console.log('Approved:', hash),
})
return (
<div>
<button onClick={() => approve(parseEther('10'))} disabled={isPending}>
{isPending ? 'Approving...' : 'Approve 10 tokens'}
</button>
<button onClick={approveMax} disabled={isPending}>
Approve unlimited
</button>
{isSuccess && <p>Approved! Tx: {hash}</p>}
{error && (
<p>
Error: {error.message}
<button onClick={reset}>Dismiss</button>
</p>
)}
</div>
)
}Options
Option
Type
Default
Description
Return Value
Field
Type
Description
Behavior
Behavior
Detail