# useJustaName

A React hook for accessing the JustaName context and service instance within components.

***

## Usage

```typescript
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 calls
* `justanameConfig`: Configuration object
* `routes`: Available API routes
* `backendUrl`: Backend URL string
* `selectedNetwork`: Selected network configuration
* `selectedEnsDomain`: Selected ENS domain
* `chainId`: Current chain ID
* `ensDomains`: Array of ENS domains
* `networks`: Array of networks
* `dev`: 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](https://github.com/JustaName-id/JustaName-sdk/blob/dc845c10af242e3ca87d95ef392516ac0bfa8b95/packages/@justaname.id/react/src/lib/providers/JustaNameProvider.tsx#L148)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.justaname.id/sdk-reference/justaname-react-sdk/functions/usejustaname.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
