Components
Network Guard
Shows a "Switch to <chain>" notice when the wallet is on a network the content doesn't support.
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.
Base-only content. Switch your network above to see the guard.
Installation
Section titled “Installation”npx shadcn@latest add @0xui/network-guardpnpm dlx shadcn@latest add @0xui/network-guardyarn dlx shadcn@latest add @0xui/network-guardbunx --bun shadcn@latest add @0xui/network-guardimport { 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.
| 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.
