diff --git a/src/useScript/useScript.demo.tsx b/src/useScript/useScript.demo.tsx index d52aeb98..8b5acfcf 100644 --- a/src/useScript/useScript.demo.tsx +++ b/src/useScript/useScript.demo.tsx @@ -10,6 +10,7 @@ export default function Component() { // Load the script asynchronously const status = useScript(`https://code.jquery.com/jquery-3.5.1.min.js`, { removeOnUnmount: false, + id: 'jq' }) useEffect(() => { diff --git a/src/useScript/useScript.ts b/src/useScript/useScript.ts index a2314bb0..5c65fd73 100644 --- a/src/useScript/useScript.ts +++ b/src/useScript/useScript.ts @@ -4,6 +4,7 @@ export type UseScriptStatus = 'idle' | 'loading' | 'ready' | 'error' export interface UseScriptOptions { shouldPreventLoad?: boolean removeOnUnmount?: boolean + id?: string; } // Cached script statuses @@ -62,6 +63,9 @@ function useScript( scriptNode = document.createElement('script') scriptNode.src = src scriptNode.async = true + if(options?.id) { + scriptNode.id = options?.id + } scriptNode.setAttribute('data-status', 'loading') document.body.appendChild(scriptNode)