Overview
TheOptions 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.
- 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()- useapi.setEnabled()instead
activationMode
'toggle' | 'hold'
default:"'toggle'"
Controls how React Grab is activated.
'toggle': Press the activation key once to activate, press again to deactivate'hold': Hold the activation key to activate, release to deactivate
- 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.
- Prevents accidental activation when using the keyboard for normal copy operations
- Only applies when the activation key is initially pressed
- Default value:
100ms
- 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.
- 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
maxContextLines
number
default:"3"
Maximum number of surrounding context lines to include when copying elements.
- Controls how much surrounding code is included in the copied snippet
- Higher values provide more context but result in longer snippets
- Set to
0to include only the element itself
maxContextLines: 3:
maxContextLines: 0:
activationKey
ActivationKey
Custom activation key configuration.
- Can be a string representing a keyboard code (e.g.,
'KeyG','KeyC') - Can be a function that receives a
KeyboardEventand returnstrueif it should activate - By default, uses
Cmd+C(Mac) orCtrl+C(Windows/Linux)
- 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.
elements: Array of selected elements
stringorPromise<string>: The content to copy to clipboard
- Allows complete customization of copied content
- Can be synchronous or asynchronous
- Overrides the default snippet generation behavior
freezeReactUpdates
boolean
default:"true"
Whether to freeze React state updates while React Grab is active.
- 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
- 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
truefor best user experience
SettableOptions
TheSettableOptions type is identical to Options except it excludes the enabled property:
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 withdata-react-grab-options:
init():
