# Network Guard

> Shows a "Switch to <chain>" notice when the wallet is on a network the content doesn't support.

- Install: `npx shadcn@latest add @0xui/network-guard`
- Registry JSON: https://0xui.io/r/network-guard.json
- Source: https://github.com/fimbul-lab/0xui/blob/main/registry/default/components/network-guard.tsx

Wrap anything that only works on certain chains. When the connected wallet is elsewhere, it shows a notice with a one-click switch. With no wallet connected, or on a supported chain, it renders its children unchanged.

## Installation

```bash
npx shadcn@latest add @0xui/network-guard
```

## Usage

```tsx
import { NetworkGuard } from "@/components/network-guard";

<NetworkGuard chainId={8453}>
  <BridgeForm />
</NetworkGuard>;

// Several chains: the first is offered as the switch target
<NetworkGuard chainId={[8453, 10]} mode="replace">…</NetworkGuard>
```

`mode="banner"` (the default) shows the notice above the content. `mode="replace"` hides the content until the network is right.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `chainId` | `number \| number[]` | — | Supported chains. |
| `mode` | `"banner" \| "replace"` | `"banner"` | Notice above the content, or instead of it. |
| `children` | `ReactNode` | — | Guarded content. |

Headless: `useNetworkGuard(chainId)` returns `wrongNetwork`, `target`, `switchToTarget()` and `phase`.
