useScript
Loads an external script into the <body> and exposes a loading signal.
Guarantees the same src is never injected more than once by generating a
deterministic id from the URL.
When to use
| ✅ Use when… | 🚫 Avoid when… |
|---|---|
|
|
Signature
const { isLoadingScript } = useScript({ src: string });Example
import { useScript } from '@apollion-dsi/core/hooks';
function MapWidget() {
const { isLoadingScript } = useScript({ src: 'https://example.com/widget.js' });
if (isLoadingScript) return <p>Loading…</p>;
return <div id="widget" />;
}See also
- Full API:
useScript(reference generated from TSDoc).