Shadcn.io is not affiliated with official shadcn/ui
React useScript Hook
React useScript hook for dynamically loading external scripts. Load status tracking, caching, SSR safe. TypeScript ready.
Load external JavaScript files dynamically with useScript. Pass a URL and get loading status: idle, loading, ready, or error. Scripts are cached globally so multiple components requesting the same script share one network request. Existing scripts are detected and reused automatically. Options for conditional loading, custom script IDs, and cleanup on unmount. Perfect for third-party integrations like analytics, maps, payments, or social widgets. SSR safe—scripts only load client-side. Works with Next.js App Router and any React framework. Handles race conditions and duplicate script tags gracefully.
React useScript Hook preview
Installation
Related Components
React useLocalStorage Hook
Persist state to localStorage
React useIsClient Hook
Check if running on client
React useEventListener Hook
Declarative DOM event handling
React useTimeout Hook
Declarative setTimeout
React useBoolean Hook
Boolean state with helpers
React useToggle Hook
Toggle between values
FAQ
Was this page helpful?
Sign in to leave feedback.