useScript
Custom hook that dynamically loads scripts and tracking their loading status.
Installation
npx sse-hooks add use-script
yarn dlx sse-hooks add use-script
pnpm dlx sse-hooks add use-script
deno run -A npm:sse-hooks add use-script
bunx 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 | - |
Additional options for controlling script loading (optional).
|
src | - |
The source URL of the script to load. Set to |
Returns
| Return Value | Default | Type |
|---|---|---|
return | - |
Hook return value |
Types Aliases
No specific type aliases defined for this component.