Skip to main content
The NearProvider component makes a Near client instance available to all components in your app via React Context.

Basic Setup

1

Create the Near client

Create your Near instance with your desired configuration. This can be done outside your component tree.
2

Wrap your app with NearProvider

Place the NearProvider at the root of your component tree.
3

Use hooks in any component

All hooks from @near-kit/react will now have access to the Near client.

Provider Props

Near
required
The Near client instance to provide to all child components.
ReactNode
required
React children to render inside the provider.

useNear Hook

Access the Near client directly when you need the full API:
useNear() will throw an error if called outside of a NearProvider. Always ensure your components are wrapped.

Framework-Specific Setup

Create a client component for the provider:
Use it in your root layout:
The @near-kit/react package includes the "use client" directive, so you don’t need to add it to your imports. However, components using the hooks must be client components.

With Wallet Connection

For dApps where users connect their own wallets, create the Near instance dynamically:
For a complete wallet integration example, see the Frontend Integration guide.

Error: Nested Provider

NearProvider throws an error if nested inside another NearProvider. This prevents accidental context shadowing.
If you need multiple Near clients (rare), manage them outside of context: