Overview
TheWormkeyOverlay component injects the Wormkey overlay control bar into React applications. It’s designed for Next.js and other React frameworks with support for client components.
Installation
Usage
Next.js App Router
With Full Script URL
With Gateway URL and Slug
API Reference
<WormkeyOverlay />
A React component that loads the Wormkey overlay script.
Full overlay script URL. When provided, this takes precedence over
gatewayUrl and slug.Example: "https://wormkey.run/.wormkey/overlay.js?slug=pale-snow-91"Gateway base URL (e.g.,
"https://wormkey.run"). Used in combination with slug to construct the script URL.Falls back to process.env.NEXT_PUBLIC_WORMKEY_GATEWAY_URL if not provided.Slug for the wormhole. If omitted when viewing at
/s/:slug, it will be automatically derived from the URL path.Behavior
Script URL Resolution
The component resolves the script URL in the following order:- Direct
scriptUrlprop - Use if provided - Constructed from
gatewayUrl+slug- If both are available - Auto-detected slug from URL - If viewing at
/s/:slugpath - Environment variable fallback - Uses
NEXT_PUBLIC_WORMKEY_GATEWAY_URL
Duplicate Prevention
The component checks for existing script tags withdata-wormkey-overlay="1" attribute to prevent loading the script multiple times.
Script Tag Attributes
defer: Ensures script loads after document parsingdata-wormkey-overlay="1": Marker to prevent duplicate injections
Render Behavior
The component rendersnull (no visible output) and only injects the script tag into the document.
TypeScript Types
WormkeyOverlayProps
Examples
Option 1: Full Script URL
Use when you have the complete script URL from CLI output:Option 2: Gateway + Slug
Use when you want to configure the gateway and slug separately:Option 3: Auto-Detection
When your app is accessed via/s/:slug path, the slug is automatically detected:
Option 4: Environment Variables
Use environment variables for configuration:Notes
- The component uses
"use client"directive for Next.js App Router compatibility - Script is injected into
document.body(notdocument.head) - Safe to use in server-side rendering (checks for
documentavailability) - Re-runs when props change via
useEffectdependencies