Nauseating Pumpkin Mush


    1.1.2 • Public • Published


    npm package

    ReactDependentScript is a simple React component used to lazily load JavaScript and CSS resources when you need them.

    When integrating with third party software it is often necessary to load that project's JavaScript or CSS on to the page. The naive way to do this is to always include it in the HTML of the page, but this means you pay the cost up front of loading that code, when your React component may never be even used.

    ReactDependentScript is a React component that wraps your component's definition, and makes sure to load the JavaScript and/or CSS first, then render your content. It ensures that the external content is only loaded once, regardless of how many times the render() function is called.

    Using it

    First install with

    npm install react-dependent-script


    yarn add react-dependent-script

    Now wrap your custom content in the component, providing an array of URLs to scripts to load, and optionally a loadingComponent property containing a component to show while loading e.g.

    import ReactDependentScript from 'react-dependent-script';
      loadingComponent={<div>jQuery is loading...</div>}
      <div>jQuery is loaded!</div>

    An alternative to rendering the child components is to provide a callback function to the renderChildren prop. This can be useful when you need to execute code that is only available after the remote script is loaded, e.g.

    import ReactDependentScript from 'react-dependent-script';
      loadingComponent={<div>jQuery is loading...</div>}
      renderChildren={() => {
        return <div>Found {$('*').length} DOM nodes on the page</div>

    You can also load other interesting libraries, like Stripe

    import ReactDependentScript from 'react-dependent-script';
      loadingComponent={<div>Loading Stripe...</div>}
      <div>Stripe script is loaded, here is your card!</div>
      <StripeProvider apiKey="pk_test_YOUR_KEY_HERE">
            onTokenCreated={data => {
              console.log('token created', data);
            onTokenCreationFailed={data => {
              console.log('token failed', data);

    See the demo/src/index.js file for more complex examples, including loading CSS files.


    This project uses the nwb module for development. After checking out the code, you have three commands available to you:

    • build builds the code into the es and lib folders. You generally don't need these.
    • start starts the demo page, which is running the demo/src/index.js code. This is your usual development environment, where you'll write examples to validate any changes.
    • clean cleans out all build artifacts


    npm i react-dependent-script


    DownloadsWeekly Downloads






    Unpacked Size

    13.5 kB

    Total Files


    Last publish


    • shaneos