Overview
TheReactGrabAPI interface provides programmatic control over React Grab. It’s returned by the init() function and includes methods to activate/deactivate React Grab, manage state, register plugins, and more.
Type Definition
Methods
activate()
Activates React Grab, allowing element selection.- Only activates if React Grab is currently enabled
- Clears any pending comment mode
- Does nothing if already active
deactivate()
Deactivates React Grab, stopping element selection.- Works even if currently in a copying state
- Cleans up all active selections and overlays
- Restores previously focused elements
toggle()
Toggles React Grab between active and inactive states.comment()
Activates comment mode, which allows adding a text prompt to copied elements.- If already in comment mode and active, deactivates React Grab
- Sets pending comment mode flag if not already active
isActive()
Checks if React Grab is currently active.trueif React Grab is active and element selection is enabledfalseotherwise
isEnabled()
Checks if React Grab is enabled.trueif React Grab is enabledfalseif disabled
- Enabled state is separate from active state
- When disabled, React Grab cannot be activated
setEnabled()
Enables or disables React Grab.boolean
required
Whether to enable or disable React Grab
- Disabling React Grab also deactivates it if currently active
- The enabled state persists in toolbar state
getToolbarState()
Gets the current toolbar state.setToolbarState()
Updates the toolbar state.Partial<ToolbarState>
required
Partial toolbar state to update
- Only provided properties are updated
- Changes are saved to localStorage
- Triggers toolbar state change callbacks
onToolbarStateChange()
Subscribes to toolbar state changes.(state: ToolbarState) => void
required
Function to call when toolbar state changes
- Unsubscribe function
dispose()
Cleans up all React Grab resources, event listeners, and state.- Removes all event listeners
- Clears all timers and intervals
- Removes overlay elements from DOM
- After calling dispose(), a new
init()call will work
copyElement()
Programmatically copies one or more elements.Element | Element[]
required
Element or array of elements to copy
Promise<boolean>- Resolves totrueif copy succeeded,falseotherwise
getSource()
Gets source information for an element.Element
required
The element to get source info for
- Returns
nullif source information cannot be determined - Requires React DevTools fiber information to be available
getStackContext()
Gets the stack context for an element.Element
required
The element to get stack context for
Promise<string>- A formatted string with the element’s component stack
getState()
Gets the current React Grab state.setOptions()
Updates React Grab options after initialization.SettableOptions
required
Options to update. Same as Options but without the
enabled property.- Cannot change the
enabledoption - usesetEnabled()instead - Changes take effect immediately
- Affects all registered plugins
registerPlugin()
Registers a new plugin with React Grab.Plugin
required
The plugin to register
- Plugins can add custom actions, hooks, and theme overrides
- See Plugin API for details
unregisterPlugin()
Unregisters a plugin by name.string
required
The name of the plugin to unregister
- Built-in plugins cannot be unregistered
- Plugin cleanup methods are called automatically
getPlugins()
Gets a list of registered plugin names.string[]- Array of plugin names
getDisplayName()
Gets the display name (component name or tag name) for an element.Element
required
The element to get the display name for
- Component name if available (e.g.,
'Button','MyComponent') - Tag name if no component name found (e.g.,
'div','button') nullif neither can be determined
