Skip to content
Docs
Hooks
useDisconnect

useDisconnect

Hook for disconnecting the connected account.

import { useDisconnect } from 'wagmi'

Usage

import { useDisconnect } from 'wagmi'

function App() {
  const { disconnect } = useDisconnect()

  return <button onClick={() => disconnect()}>Disconnect</button>
}

Return Value

{
  disconnect: () => void
  disconnectAsync: () => Promise<void>
  error?: Error
  isError: boolean
  isIdle: boolean
  isLoading: boolean
  isSuccess: boolean
  reset: () => void
  status: "error" | "idle" | "loading" | "success"
}

Configuration

onError (optional)

Function to invoke when an error is thrown while disconnecting.

import { useDisconnect } from 'wagmi'

function App() {
  const disconnect = useDisconnect({
    onError(error) {
      console.log('Error', error)
    },
  })
}

onMutate (optional)

Function fires before disconnect function. Value returned from this function will be passed to both onError and onSettled functions in event of a disconnect failure.

import { useDisconnect } from 'wagmi'

function App() {
  const disconnect = useDisconnect({
    onMutate(args) {
      console.log('Mutate', args)
    },
  })
}

onSettled (optional)

Function to invoke when disconnect is settled (either successfully disconnected, or an error has thrown).

import { useDisconnect } from 'wagmi'

function App() {
  const disconnect = useDisconnect({
    onSettled(data, error) {
      console.log('Settled', { data, error })
    },
  })
}

onSuccess (optional)

Function to invoke when disconnect is successful.

import { useDisconnect } from 'wagmi'

function App() {
  const disconnect = useDisconnect({
    onSuccess(data) {
      console.log('Success', data)
    },
  })
}