# react-script-loader-hoc

> A higher-order React component that assists in the asynchronous loading of third party JS libraries (eg. Stripe.js)

Latest version **1.2.2** (published 2019-03-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-script-loader-hoc
pnpm add react-script-loader-hoc
yarn add react-script-loader-hoc
bun add react-script-loader-hoc
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2019-03-21 |
| First published | 2017-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 389.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 65 |
| Author | Nick Rogers |
| Maintainers | sesilio |
| Keywords | react, reactjs, react-component, script-loader, async, stripe, loader, asynchronous, stripe-react-elements, higher-order-component |

## Links

- npm: https://www.npmjs.com/package/react-script-loader-hoc
- Repository: https://github.com/sesilio/react-script-loader-hoc
- npm.io page: https://npm.io/package/react-script-loader-hoc

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^16.8.4
- [hoist-non-react-statics](https://npm.io/package/hoist-non-react-statics.md) ^2.3.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.2.2 (latest) — 2019-03-21
- 1.2.1 — 2018-10-26
- 1.1.0 — 2018-01-03
- 1.0.1 — 2017-11-06
- 1.0.0 — 2017-10-12
- 0.3.1 — 2017-10-05
- 0.3.0 — 2017-10-05
- 0.2.0 — 2017-10-04
- 0.1.1 — 2017-10-04
- 0.1.0 — 2017-10-04

## README

# react-script-loader-hoc
[![npm version](https://img.shields.io/badge/npm-v1.2.1-brightgreen.svg)](https://www.npmjs.com/package/react-script-loader-hoc) [![license](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/sesilio/react-script-loader-hoc/blob/master/LICENSE)

A higher-order React component that assists in the asynchronous loading of third party JS libraries (eg. Stripe.js)

### Installation
```
yarn add react-script-loader-hoc
```
or
```
npm install --save react-script-loader-hoc
```

### Example usage with Stripe React Elements
Simple example of asynchronously loading the Stripe.js library. The `LoadIcon` component will be rendered until the Stripe.js library loads asynchronously, at which point the `LoadIcon` will be replaced by the `StripeProvider`.
```jsx
  import React from 'react';
  import ScriptLoader from 'react-script-loader-hoc';
  import { StripeProvider, Elements } from 'react-stripe-elements';
  import { LoadIcon, CheckoutForm } from '../components';

  const StripePayment = ({ scriptsLoadedSuccessfully }) => {
    if (!scriptsLoadedSuccessfully) return <LoadIcon />;

    return (
      <StripeProvider apiKey="pk_test_12345">
        <Elements>
          <CheckoutForm />
        </Elements>
      </StripeProvider>
    );
  };

  export default ScriptLoader('https://js.stripe.com/v3/')(StripePayment);
```

### API
`ScriptLoader` takes `n` string arguments, each of which should be a URL of a javascript resource to load. The higher-order `ScriptLoader` component will pass two boolean-valued props to the wrapped component:
 - `scriptsLoaded`
 - `scriptsLoadedSuccessfully`

`scriptsLoaded` will be `false` until either all scripts load successfully or one or more of the scripts fail to load (eg. if a 404 occurs), at which point it will be `true`. `scriptsLoadedSuccessfully` will be `true` if all scripts load successfully or `false` if either an error occurs or if some scripts are still loading. `scriptsLoadedSuccessfully` will always be `false` while `scriptsLoaded` is false.

---
_Source: https://npm.io/package/react-script-loader-hoc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
