useUpdateChanges
A React hook for detecting changes between current and new subname records before updating.
Usage
import { useUpdateChanges } from '@justaname.id/react'
function UpdateChangesComponent() {
const {
changes,
canUpdateEns,
isUpdateChangesLoading
} = useUpdateChanges({
ens: 'alice.justaname.eth',
text: [
{ key: 'description', value: 'New description' }
],
addresses: [
{ address: '0x123...', coinType: 60 }
]
})
if (isUpdateChangesLoading) return <div>Analyzing changes...</div>
return (
<div>
<h3>Changes Detected</h3>
<p>Text Records Changed: {changes?.changedTexts?.length || 0}</p>
<p>Addresses Changed: {changes?.changedAddresses?.length || 0}</p>
<p>Content Hash Changed: {changes?.changedContentHash ? 'Yes' : 'No'}</p>
<p>Can Update: {canUpdateEns ? 'Yes' : 'No'}</p>
</div>
)
}
Returns
An object containing:
changes
: Object with detected changes:changedTexts
: Array of text records that changedchangedAddresses
: Array of addresses that changedchangedContentHash
: Changed content hash (if any)
canUpdateEns
: Boolean indicating if there are any changes to applyisUpdateChangesLoading
: Boolean indicating if analysis is in progressisUpdateChangesPending
: Boolean for pending stateisUpdateChangesFetching
: Boolean for fetching stategetUpdateChanges
: Function to manually get changescheckIfUpdateIsValid
: Function to check if update is validrefetchUpdateChanges
: Function to refetch changes
Parameters
Optional configuration object:
ens?
: The ENS name to check changes fortext?
: Array of new text records{ key: string, value: string }[]
addresses?
: Array of new address records{ address: string, coinType: number }[]
contentHash?
: New content hash stringchainId?
: The chain ID to use
Defined in
packages/@justaname.id/react/src/lib/hooks/subname/useUpdateChanges.ts:49
Last updated
Was this helpful?