# react-with-external-script

> High Order Component to load external scripts

Latest version **1.0.0** (published 2018-11-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-with-external-script
pnpm add react-with-external-script
yarn add react-with-external-script
bun add react-with-external-script
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-11-13 |
| First published | 2018-11-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 14.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Javier Vidal |
| Maintainers | javidalpe |
| Keywords | react, scripts, loader, hoc |

## Links

- npm: https://www.npmjs.com/package/react-with-external-script
- Repository: https://github.com/javidalpe/react-with-external-script
- Homepage: https://github.com/javidalpe/react-with-external-script#readme
- Issues: https://github.com/javidalpe/react-with-external-script/issues
- npm.io page: https://npm.io/package/react-with-external-script

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^16.6.3
- [react-dom](https://npm.io/package/react-dom.md) ^16.6.3

## 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.0.0 (latest) — 2018-11-13

## README

# Intro
This [High Order Component](https://reactjs.org/docs/higher-order-components.html) simplifies creating React components whose rendering depends on 
dynamically loaded scripts. 

Your wrapped React component will be mount once the external script is loaded.

### Installation

To get started, you can simply install it via npm.

```bash
npm i --save react-with-external-script
```

### Example usage
Google Maps Hello World
````javascript
class Map extends React.Component {
  componentDidMount() {
      // Initialize Google Maps
      new google.maps.Map(document.getElementById('map'), {
                center: {lat: -34.397, lng: 150.644},
                zoom: 8
              });
    }
  }
  render () {
    return <div id='map' />
  }
}

export default withExternalScript('https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap', Map)
````

D3 Hello World
````javascript
class D3Chart extends React.Component {
  componentDidMount() {
      // Initialize d3 chart
      d3.select(".chart").append("span")
          .text("Hello, world!");
    }
  }
  render () {
    return <div className='chart' />
  }
}

export default withExternalScript('https://cdnjs.cloudflare.com/ajax/libs/d3/4.12.0/d3.min.js', D3Chart)
````

### Test

````
npm test
````

### License

MIT

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