Skip to content

useRefreshSession

Hook for manually refreshing the current session

Import

import { useRefreshSession } from '@zerodev/wallet-react'

Usage

import { useRefreshSession } from '@zerodev/wallet-react'
 
function SessionControls() {
  const refreshSession = useRefreshSession()
 
  return (
    <button
      onClick={() => refreshSession.mutateAsync({})}
      disabled={refreshSession.isPending}
    >
      {refreshSession.isPending ? 'Refreshing...' : 'Refresh Session'}
    </button>
  )
}

Parameters

This hook takes an empty object {} as its mutation variable. An optional connector can be provided if you have multiple connectors configured.

connector

Connector | undefined

The Wagmi connector to refresh the session for. If omitted, uses the currently active connector.

Return Types

TanStack Query mutation docs

mutate

(variables: { connector?: Connector }) => void

The mutation function to refresh the session.

mutateAsync

(variables: { connector?: Connector }) => Promise<unknown>

Similar to mutate but returns a promise. Resolves with the refreshed session data.

data

unknown

The refreshed session data.

error

Error | null

The error object for the mutation, if an error was encountered.

isError / isIdle / isPending / isSuccess

boolean

Boolean variables derived from status.

isPaused

boolean

  • will be true if the mutation has been paused.
  • see Network Mode for more information.

status

'idle' | 'pending' | 'error' | 'success'

  • 'idle' initial status prior to the mutation function executing.
  • 'pending' if the mutation is currently executing.
  • 'error' if the last mutation attempt resulted in an error.
  • 'success' if the last mutation attempt was successful.

reset

() => void

A function to clean the mutation internal state (e.g. it resets the mutation to its initial state).