Module: use-captain-action
Table of contents
Functions
Functions
useCaptainAction
▸ useCaptainAction(action
): void
A custom React hook that uses URL query parameters to perform specified actions on elements identified by their data-captainid
.
The hook listens for changes in the URL's action
query parameter and parses its value to execute supported commands:
- "focus": Sets focus on the targeted element.
- "click": Triggers a click event on the targeted element.
- "type": Sets the value of an input element and dispatches an input event to simulate typing.
This hook is intended for use in Next.js applications to dynamically handle UI interactions based on URL state, enhancing user experience by enabling direct interaction triggers via URL navigation.
Parameters
Name | Type |
---|---|
action | any |
Returns
void
Example
// Assuming a component within a Next.js application:
useCaptainAction();
// Given a URL like: /page?action=click:data-captainid-123
// Automatically clicks the element with `data-captainid="data-captainid-123"`
Defined in
react/dist/esm/use-captain-action/index.js:21