useAddressEnsNames

A React hook for fetching ENS names and their records associated with a specific Ethereum address.


Usage

import { useAddressEnsNames } from '@justaname.id/react'

// Basic usage
function AddressEnsNamesComponent() {
  const { 
    addressEnsNames, 
    isAddressEnsNamesPending, 
    refetchAddressEnsNames 
  } = useAddressEnsNames({
    address: '0x1234567890abcdef1234567890abcdef12345678'
  })
  
  if (isAddressEnsNamesPending) return <div>Loading ENS names...</div>
  
  return (
    <div>
      <h3>ENS Names for Address</h3>
      {addressEnsNames?.map((record, index) => (
        <div key={index}>
          <strong>{record.ens}</strong>
          <p>Avatar: {record.sanitizedRecords?.avatar}</p>
          <p>Description: {record.sanitizedRecords?.description}</p>
        </div>
      ))}
      <button onClick={() => refetchAddressEnsNames()}>Refresh</button>
    </div>
  )
}

Returns

UseAddressEnsNamesResult - An object containing:

  • addressEnsNames: Array of Records objects containing ENS names and their records

  • isAddressEnsNamesPending: Boolean indicating if the data is being fetched

  • isAddressEnsNamesFetching: Boolean indicating if the data is being refetched

  • isAddressEnsNamesLoading: Boolean indicating if the data is loading for the first time

  • getEnsNamesForAddress: Function to manually fetch ENS names for an address

  • refetchAddressEnsNames: Function to manually refetch the data

Parameters

  • params?: UseAddressEnsNamesParams - Optional parameters:

    • address: Ethereum address to fetch ENS names for

    • chainId: Chain ID (defaults to provider's chainId)

    • enabled: Whether to enable the query (defaults to true)

Defined in

packages/@justaname.id/react/src/lib/hooks/ens/useAddressEnsNames.ts:35

Last updated

Was this helpful?