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:Framework-Specific Setup
- Next.js (App Router)
- Next.js (Pages Router)
- Vite / CRA
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.