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 ofRecords
objects containing ENS names and their recordsisAddressEnsNamesPending
: Boolean indicating if the data is being fetchedisAddressEnsNamesFetching
: Boolean indicating if the data is being refetchedisAddressEnsNamesLoading
: Boolean indicating if the data is loading for the first timegetEnsNamesForAddress
: Function to manually fetch ENS names for an addressrefetchAddressEnsNames
: Function to manually refetch the data
Parameters
params?:
UseAddressEnsNamesParams
- Optional parameters:address
: Ethereum address to fetch ENS names forchainId
: 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?