{"library":"react-script-hook","title":"react-script-hook","description":"A React hook for dynamically loading external scripts and tracking their load state. Current stable version is 1.7.2. The package is actively maintained with regular updates. It provides a simple API: call useScript with a script URL and get loading/error states. Key differentiators: automatic deduplication (multiple components loading the same script share a single request), support for onload callbacks, a checkForExisting flag for environments where the script may already be present, and conditionally loading by setting src to null. Includes TypeScript definitions and supports React 16.8.6 through 18.","language":"javascript","status":"active","last_verified":"Mon Apr 27","install":{"commands":["npm install react-script-hook"],"cli":null},"imports":["import useScript from 'react-script-hook'","import { useScript } from 'react-script-hook'","import type { UseScriptOptions } from 'react-script-hook'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import React from 'react';\nimport { StripeProvider } from 'react-stripe-elements';\nimport useScript from 'react-script-hook';\nimport MyCheckout from './my-checkout';\n\nfunction App() {\n  const [loading, error] = useScript({ src: 'https://js.stripe.com/v3/' });\n\n  if (loading) return <h3>Loading Stripe API...</h3>;\n  if (error) return <h3>Failed to load Stripe API: {error.message}</h3>;\n\n  return (\n    <StripeProvider apiKey={process.env.STRIPE_PUBLIC_KEY ?? ''}>\n      <MyCheckout />\n    </StripeProvider>\n  );\n}\n\nexport default App;","lang":"javascript","description":"Demonstrates loading the Stripe.js script dynamically using useScript and conditionally rendering a StripeProvider only after the script loads.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}