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

ParameterTypeDescriptionDefault
src`stringnull`The source URL of the script to load. Set to null or omit to prevent loading (optional).
[options]UseScriptOptionsAdditional options for controlling script loading (optional).-

Return Value

ValueTypeDescription
returnUseScriptStatusThe status of the script loading, which can be one of 'idle', 'loading', 'ready', or 'error'.

On this page