react-weblibrary
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

react-weblibrary

Another react hook for loading scripts from the web

import { useWebLibrary } from 'react-weblibrary'

function MyComponent() {
   // Expect the script from https://example.com/someLibrary to define `window.$`.
   // If the global exists (e.g. because the script is already requested in <head>), the script will not be requested again.
   const [someLibrary, status] = useWebLibrary('$', 'https://example.com/someLibrary')

   if (!someLibrary) {
      return status === 'try' ? 'Still loading...' : 'Something went wrong.'
   }

   someLibrary.someFunction()
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.4
    575
    • latest

Version History

Package Sidebar

Install

npm i react-weblibrary

Weekly Downloads

678

Version

1.0.4

License

MIT

Unpacked Size

6.19 kB

Total Files

11

Last publish

Collaborators

  • ph.fritsche