Documentation for agents: an index at /llms.txt, every docs page in one file at /llms-full.txt, and Markdown for any docs page by adding .md to its URL.

Skip to Content
ensforgeReact

Components

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

Components exported from @ensforge/react. See Set up the provider.

Components

EnsforgeProvider

Provides an ensforge client to the hooks below it.

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.
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

Unstable

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

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

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.

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.

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

Props of EnsforgeProvider.

type EnsforgeProviderProps
OptionTypeDefaultDescription
client (required)Ensforge.ClientThe 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.
defaultsFreshnessFreshness for every read below, unless a hook sets its own.
registrybooleantrueCreate 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.
childrenReactNode

ReadErrorResetBoundaryProps

Props of ReadErrorResetBoundary.

type ReadErrorResetBoundaryProps
OptionTypeDefaultDescription
children (required)ReactNode | ((reset: ReadErrorReset) => ReactNode)The subtree, or a function of the reset handle for wiring it to an error boundary.

Was this page helpful?