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 usingwindow.__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
TheReactGrab 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 globalwindow.__REACT_GRAB__ object.
API Reference
TheReactGrabAPI 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 usinguseEffect:
Plugin Actions
Actions can appear in the context menu or toolbar based on thetarget field:
Plugin Configuration
Plugins can provide any combination of:actions— Context menu and/or toolbar items (usetarget: "toolbar"for toolbar)hooks— Lifecycle callbacks like:onActivate— Called when React Grab is activatedonElementSelect— Called when an element is selectedonCopySuccess— Called when content is copiedtransformCopyContent— Modify copied content
theme— Partial theme overridesoptions— Override default options likeactivationModeorkeyHoldDurationsetup(api)— Receives the fullReactGrabAPIand 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 toapp/layout.tsx:
Next.js Pages Router
Add topages/_document.tsx:
Vite
Add toindex.html:
Webpack
Install and import in your entry file:src/index.tsx or src/main.tsx:
Related
- See Plugin Types Reference for full
Plugininterface details - See CLI Commands for installation commands
