SSE Hooks

useScript

GitHub
Custom hook that dynamically loads scripts and tracking their loading status.

Installation

npx sse-hooks add use-script

Usage

example.ts
import { useScript } from "./{hooks file}";

const scriptStatus = useScript("https://example.com/script.js", {
  removeOnUnmount: true,
});
// Access the status of the script loading (e.g., 'loading', 'ready', 'error').

API

Parameters

Prop Default Type
options-

UseScriptOptions

Additional options for controlling script loading (optional).

src-

string | null

The source URL of the script to load. Set to null or omit to prevent loading (optional).

Returns

Return Value Default Type
return-

"idle" | "loading" | "ready" | "error"

Hook return value

Types Aliases

No specific type aliases defined for this component.

Changelog

c165d — feat: enhance useRoleGuard and useSSR hooks with additional options and documentation

30da4 — feat: add new hooks and their metadata

cf13e — feat: add custom hooks for step navigation, ternary dark mode, timeout, toggle, unmount, and window size

Built with Love • © 2026