useJustaName
A React hook for accessing the JustaName context and service instance within components.
Usage
import { useJustaName } from '@justaname.id/react'
function MyComponent() {
const { justaname, chainId, backendUrl } = useJustaName()
const handleAction = async () => {
if (justaname) {
// Use the justaname service instance
const result = await justaname.subnames.getSubname({
subname: 'alice.justaname.eth',
chainId: 1
})
console.log('Result:', result)
}
}
return (
<div>
<h3>JustaName Service</h3>
<p>Chain ID: {chainId}</p>
<p>Backend URL: {backendUrl}</p>
<button onClick={handleAction}>
Get Subname
</button>
</div>
)
}
Returns
An object containing:
justaname
: JustaName service instance for API callsjustanameConfig
: Configuration objectroutes
: Available API routesbackendUrl
: Backend URL stringselectedNetwork
: Selected network configurationselectedEnsDomain
: Selected ENS domainchainId
: Current chain IDensDomains
: Array of ENS domainsnetworks
: Array of networksdev
: Development mode flag
Throws
If the hook is used outside a JustaNameProvider, it will throw an error.
Defined in
packages/@justaname.id/react/src/lib/providers/JustaNameProvider.tsx:148
Last updated
Was this helpful?