> For the complete documentation index, see [llms.txt](https://docs.yo.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yo.xyz/integrations/integration-guides/sdk/react/overview.md).

# Overview

React hooks and providers for the Yo yield protocol, built on `@yo-protocol/core`, wagmi, and TanStack Query.

## Key Concepts

| Concept           | Description                                                                                                                                             |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **YieldProvider** | Context provider that creates and exposes a `YoClient`. Must sit inside `WagmiProvider` and `QueryClientProvider`.                                      |
| **Read hooks**    | `useVault`, `useVaults`, `useUserBalance`, `useVaultHistory` — backed by TanStack Query with automatic caching, refetching, and stale-while-revalidate. |
| **Action hooks**  | `useDeposit`, `useRedeem`, `useApprove` — mutation-style hooks with loading, error, and transaction confirmation tracking.                              |
| **YoKitProvider** | Optional theming provider for pre-built UI components.                                                                                                  |

## Setup

```tsx
import { WagmiProvider } from 'wagmi'
import { QueryClientProvider, QueryClient } from '@tanstack/react-query'
import { YieldProvider } from '@yo-protocol/react'
import { config } from './wagmi'

const queryClient = new QueryClient()

export function Providers({ children }: { children: React.ReactNode }) {
  return (
    <WagmiProvider config={config}>
      <QueryClientProvider client={queryClient}>
        <YieldProvider>
          {children}
        </YieldProvider>
      </QueryClientProvider>
    </WagmiProvider>
  )
}
```

{% hint style="warning" %}
**Provider order matters**

`YieldProvider` must be nested inside both `WagmiProvider` and `QueryClientProvider`. It reads the wagmi config and query client from context.
{% endhint %}

## Usage Example

```tsx
import { useVault, useDeposit } from '@yo-protocol/react'
import { parseEther } from 'viem'

function DepositCard() {
  const { vault, isLoading } = useVault('yoETH')
  const { deposit, isPending, isSuccess } = useDeposit({ vault: 'yoETH' })

  if (isLoading) return <p>Loading vault...</p>

  return (
    <div>
      <h2>{vault?.name}</h2>
      <p>Total assets: {vault?.totalAssets.toString()}</p>
      <button onClick={() => deposit(parseEther('0.1'))} disabled={isPending}>
        {isPending ? 'Depositing...' : 'Deposit 0.1 ETH'}
      </button>
      {isSuccess && <p>Deposit confirmed!</p>}
    </div>
  )
}
```

## Exports

### Providers

| Export           | Description                                                  |
| ---------------- | ------------------------------------------------------------ |
| `YieldProvider`  | Core context provider — creates `YoClient` from wagmi config |
| `useYoClient`    | Access the underlying `YoClient` instance                    |
| `useYieldConfig` | Access the provider configuration                            |
| `YoKitProvider`  | Optional theming provider for pre-built UI                   |

### Read Hooks

| Hook                     | Returns                         | Description                      |
| ------------------------ | ------------------------------- | -------------------------------- |
| `useVault(name)`         | `{ vault, isLoading, error }`   | Single vault state + snapshot    |
| `useVaults()`            | `{ vaults, isLoading, error }`  | All vaults for the current chain |
| `useUserBalance(vault)`  | `{ balance, isLoading, error }` | Connected user's vault position  |
| `useVaultHistory(vault)` | `{ history, isLoading, error }` | APY and TVL timeseries data      |

### Action Hooks

| Hook                    | Returns                                    | Description                          |
| ----------------------- | ------------------------------------------ | ------------------------------------ |
| `useDeposit({ vault })` | `{ deposit, isPending, isSuccess, error }` | Deposit assets via gateway           |
| `useRedeem({ vault })`  | `{ redeem, isPending, isSuccess, error }`  | Redeem shares for assets via gateway |
| `useApprove({ token })` | `{ approve, isPending, isSuccess, error }` | Approve token spending               |

## Next Steps

* [YieldProvider](broken://pages/6d0d2f8b4e967cf9c46c81d304aa74a01b0d9bf2) — Provider configuration and options
* [Hooks Reference](broken://pages/f3be6a35f60074357529ed440efb10df8091a499) — Full hook API reference starting with useVault
* [Wagmi Setup](file:///3007190/guides/wagmi-setup.md) — Configuring wagmi for use with @yield


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.yo.xyz/integrations/integration-guides/sdk/react/overview.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.
