useRecords
A React hook for fetching ENS records (text records, addresses, content hash) for a given ENS name.
Usage
import { useRecords } from '@justaname.id/react'
function RecordsComponent() {
const { records, isRecordsLoading, refetchRecords } = useRecords({
ens: 'alice.eth',
chainId: 1
})
if (isRecordsLoading) return <div>Loading records...</div>
return (
<div>
<h3>Records for alice.eth</h3>
<div>
<h4>Text Records</h4>
{records?.records?.texts?.map((text, index) => (
<div key={index}>
<strong>{text.key}:</strong> {text.value}
</div>
))}
</div>
<div>
<h4>Addresses</h4>
{records?.records?.coins?.map((coin, index) => (
<div key={index}>
<strong>Coin Type {coin.id}:</strong> {coin.value}
</div>
))}
</div>
<button onClick={() => refetchRecords()}>Refresh</button>
</div>
)
}
Returns
An object containing:
records
: Records object with:ens
: The ENS nameisJAN
: Boolean indicating if it's a JustaName subnamerecords
: Object containing resolver address, text records, addresses, content hashsanitizedRecords
: Sanitized version of the records
isRecordsPending
: Boolean indicating if the query is pendingisRecordsFetching
: Boolean indicating if the query is fetchingisRecordsLoading
: Boolean indicating if the query is loadinggetRecords
: Function to manually get recordsrefetchRecords
: Function to manually refetch the recordsrecordsStatus
: Status of the query ('error' | 'success' | 'pending')
Parameters
Optional parameters:
ens?
: The ENS name to fetch records forchainId?
: The chain ID to use (optional, defaults to provider chain ID)enabled?
: Boolean to enable/disable the query (optional, defaults to true)skipQueue?
: Boolean to skip the records queue (optional)
Defined in
packages/@justaname.id/react/src/lib/hooks/records/useRecords.ts:68
Last updated
Was this helpful?