Skip to main content

Overview

React Grab provides a React component and global API for integrating element selection functionality into your application. You can access the API from React components using window.__REACT_GRAB__ and register plugins with custom behavior.

ReactGrab Component

The <ReactGrab> component automatically initializes React Grab in your application.

Usage

Import and use the component in your React application:

Props

The ReactGrab component accepts Options for configuration:

Activation Behavior

React Grab only activates in development mode by default:
  • Development: Automatically enabled when process.env.NODE_ENV !== "production"
  • Production: Only enabled when URL has query parameter ?react-grab=true

Accessing the API

Access the React Grab API through the global window.__REACT_GRAB__ object.

API Reference

The ReactGrabAPI interface is available at window.__REACT_GRAB__ after initialization:

Plugin Registration

Plugins extend React Grab with custom actions, lifecycle hooks, and theme overrides.

Basic Plugin Example

Register a plugin using vanilla JavaScript:

React Plugin Registration

Register plugins in React components using useEffect:
1

Import useEffect

Import React’s useEffect hook:
2

Register in useEffect

Register your plugin after React Grab loads:
3

Clean up on unmount

Always unregister plugins when the component unmounts:

Plugin Actions

Actions can appear in the context menu or toolbar based on the target field:

Plugin Configuration

Plugins can provide any combination of:
  • actions — Context menu and/or toolbar items (use target: "toolbar" for toolbar)
  • hooks — Lifecycle callbacks like:
    • onActivate — Called when React Grab is activated
    • onElementSelect — Called when an element is selected
    • onCopySuccess — Called when content is copied
    • transformCopyContent — Modify copied content
  • theme — Partial theme overrides
  • options — Override default options like activationMode or keyHoldDuration
  • setup(api) — Receives the full ReactGrabAPI and can return additional config or cleanup function

Complete Plugin Example

TypeScript Support

React Grab includes full TypeScript definitions:

Framework Examples

Next.js App Router

Add to app/layout.tsx:

Next.js Pages Router

Add to pages/_document.tsx:

Vite

Add to index.html:

Webpack

Install and import in your entry file:
Then add to src/index.tsx or src/main.tsx: