# Components

> For the complete documentation index, see [llms.txt](https://ensforge.com/llms.txt).

Look up EnsforgeProvider and the read error and hydration boundary components of @ensforge/react, with their props and examples.

Source: https://ensforge.com/docs/reference/react/components

Components exported from `@ensforge/react`. See [Set up the provider](/docs/react/set-up-the-provider).

## Components [#components]

### `EnsforgeProvider` [#ensforgeprovider]

Provides an ensforge client to the hooks below it.

```ts
function EnsforgeProvider({ client, defaults, registry = true, children, }: EnsforgeProviderProps): ReactNode
```

Use once near the root, inside the wagmi providers when the app has them. Nest another with
`registry={false}` for a second chain.

- Hooks run actions with this client; they do not need its action groups (`extend`).
- It renders an Effect Atom `RegistryProvider`, so each server request gets its own cache.

```tsx title="A wagmi app"
import { EnsforgeProvider } from "@ensforge/react"
import { Ensforge } from "@ensforge/sdk/wagmi"

const ens = Ensforge.fromWagmi(wagmiConfig)

export function Providers({ children }: { children: React.ReactNode }) {
  return <EnsforgeProvider client={ens}>{children}</EnsforgeProvider>
}
```

### `HydrationBoundary` [#hydrationboundary]

**Unstable**

Provides a React hydration boundary that loads dehydrated Atom values into
the current Atom registry.

```ts
const HydrationBoundary: React.FC<HydrationBoundaryProps>
```

Use to apply dehydrated Atom state to a React subtree that reads from the
nearest `RegistryContext`.

New Atom values are hydrated during render so descendants can read them
immediately, while values for existing Atoms are deferred until after commit
so transition data does not update the current UI before React accepts it.

### `ReadErrorResetBoundary` [#readerrorresetboundary]

Scopes error resets of `useSuspenseRead`: a failure the reads below threw to an error boundary
is rethrown, from the cache, until `reset` is called; after that they read again. Place it
around the error boundary and call `reset` when that boundary resets. Like React Query's
`QueryErrorResetBoundary`.

```ts
function ReadErrorResetBoundary({ children }: ReadErrorResetBoundaryProps)
```

Use with `useSuspenseRead` and an error boundary that can reset, so "try again" fetches again
instead of showing the cached error. Without a boundary `useReadErrorReset` resets every read
in the app.

```tsx title="Wiring an error boundary's reset"
import { Component, Suspense, type ReactNode } from "react"
import { ReadErrorResetBoundary, useSuspenseRead } from "@ensforge/react"
import { Actions } from "@ensforge/sdk"

// Any error boundary with a reset callback works, such as react-error-boundary's `onReset`.
class Boundary extends Component<{ children: ReactNode; onReset: () => void }, { failed: boolean }> {
  override state = { failed: false }
  static getDerivedStateFromError() {
    return { failed: true }
  }
  override render() {
    if (!this.state.failed) return this.props.children
    return (
      <button onClick={() => { this.props.onReset(); this.setState({ failed: false }) }}>
        Try again
      </button>
    )
  }
}

function Owner({ name }: { name: string }) {
  const { data } = useSuspenseRead(Actions.name.get, { name })
  return <span>{data.owner}</span>
}

export const View = ({ name }: { name: string }) => (
  <ReadErrorResetBoundary>
    {({ reset }) => (
      <Boundary onReset={reset}>
        <Suspense fallback="loading">
          <Owner name={name} />
        </Suspense>
      </Boundary>
    )}
  </ReadErrorResetBoundary>
)
```

### `EnsforgeProviderProps` [#ensforgeproviderprops]

Props of [`EnsforgeProvider`](/docs/reference/react/components#ensforgeprovider).

```ts
type EnsforgeProviderProps
```

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `client` (required) | `Ensforge.Client` |  | The client hooks use, as is: `Ensforge.create(…)`, or `Ensforge.fromWagmi(config)`. Writes ENS makes on other chains (L2 primary names) need them in its `chains`, which `fromWagmi` fills from the wagmi config's chains. |
| `defaults` | `Freshness` |  | Freshness for every read below, unless a hook sets its own. |
| `registry` | `boolean` | `true` | Create an atom registry for the subtree. Pass `false` when the app already renders a `RegistryProvider` (to share atoms with it) or when nesting providers for other chains. |
| `children` | `ReactNode` |  |  |

### `ReadErrorResetBoundaryProps` [#readerrorresetboundaryprops]

Props of [`ReadErrorResetBoundary`](/docs/reference/react/components#readerrorresetboundary).

```ts
type ReadErrorResetBoundaryProps
```

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `children` (required) | `ReactNode \| ((reset: ReadErrorReset) => ReactNode)` |  | The subtree, or a function of the reset handle for wiring it to an error boundary. |