Skip to main content

Overview

The Options interface defines the configuration options you can pass to the init() function to customize React Grab’s behavior.

Type Definition

Properties

enabled

boolean
default:"true"
Whether React Grab is enabled on initialization.
Description:
  • When false, init() returns a no-op API where all methods are safe to call but perform no actions
  • Useful for conditionally disabling React Grab in production or specific environments
  • Cannot be changed after initialization via setOptions() - use api.setEnabled() instead
Example:

activationMode

'toggle' | 'hold'
default:"'toggle'"
Controls how React Grab is activated.
Values:
  • 'toggle': Press the activation key once to activate, press again to deactivate
  • 'hold': Hold the activation key to activate, release to deactivate
Example:
Notes:
  • In 'toggle' mode, React Grab stays active until explicitly deactivated
  • In 'hold' mode, you must continuously hold the activation key

keyHoldDuration

number
default:"100"
Duration in milliseconds to hold the activation key before activation.
Description:
  • Prevents accidental activation when using the keyboard for normal copy operations
  • Only applies when the activation key is initially pressed
  • Default value: 100ms
Example:
Notes:
  • If you press and release the key before this duration, normal copy behavior occurs
  • If you hold for longer than this duration, React Grab activates

allowActivationInsideInput

boolean
default:"true"
Whether to allow activation when focus is inside an input field.
Description:
  • When true, React Grab can be activated even when an input, textarea, or contenteditable element is focused
  • When false, activation is blocked in these contexts to avoid interfering with normal text editing
Example:

maxContextLines

number
default:"3"
Maximum number of surrounding context lines to include when copying elements.
Description:
  • Controls how much surrounding code is included in the copied snippet
  • Higher values provide more context but result in longer snippets
  • Set to 0 to include only the element itself
Example:
Example Output: With maxContextLines: 3:
With maxContextLines: 0:

activationKey

ActivationKey
Custom activation key configuration.
Type Definition:
Description:
  • Can be a string representing a keyboard code (e.g., 'KeyG', 'KeyC')
  • Can be a function that receives a KeyboardEvent and returns true if it should activate
  • By default, uses Cmd+C (Mac) or Ctrl+C (Windows/Linux)
Example - String:
Example - Function:
Example - Alt Key:
Notes:
  • The modifier key (Cmd/Ctrl) is still required unless you override it in a custom function
  • Using a commonly-used key combination may interfere with browser shortcuts

getContent

(elements: Element[]) => Promise<string> | string
Custom function to generate content when copying elements.
Parameters:
  • elements: Array of selected elements
Returns:
  • string or Promise<string>: The content to copy to clipboard
Description:
  • Allows complete customization of copied content
  • Can be synchronous or asynchronous
  • Overrides the default snippet generation behavior
Example - HTML:
Example - JSON:
Example - Async:

freezeReactUpdates

boolean
default:"true"
Whether to freeze React state updates while React Grab is active.
Description:
  • Prevents React components from re-rendering while selecting elements
  • Stops UI changes that could interfere with element selection
  • Uses React Fiber internals to pause component updates
Example:
Notes:
  • When true, animations and state changes are paused during selection
  • When false, the UI can change while you’re selecting, which may be disorienting
  • Recommended to keep this true for best user experience

SettableOptions

The SettableOptions type is identical to Options except it excludes the enabled property:
Usage: Used with api.setOptions() to update options after initialization:

Complete Example

Here’s a comprehensive example using multiple options:

Environment Configuration

You can also configure options via a script tag with data-react-grab-options:
These options are merged with options passed to init():