useScript
Custom hook that dynamically loads scripts and tracking their loading status.
Custom hook that dynamically loads scripts and tracking their loading status.
Usage
import { useScript } from "@tilt-legal/cubitt-components/utilities/hooks";
const scriptStatus = useScript('https://example.com/script.js', { removeOnUnmount: true });
// Access the status of the script loading (e.g., 'loading', 'ready', 'error').API
Signature
declare function useScript(src: string | null, options?: UseScriptOptions): UseScriptStatus;Parameters
| Parameter | Type | Description | Default |
|---|---|---|---|
src | `string | null` | The source URL of the script to load. Set to null or omit to prevent loading (optional). |
[options] | UseScriptOptions | Additional options for controlling script loading (optional). | - |
Return Value
| Value | Type | Description |
|---|---|---|
return | UseScriptStatus | The status of the script loading, which can be one of 'idle', 'loading', 'ready', or 'error'. |