Socket
Socket
Sign inDemoInstall

react-async-load-script

Package Overview
Dependencies
9
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-async-load-script

Async script loader HOC for React


Version published
Maintainers
1
Install size
173 kB
Created

Readme

Source

React async script loader

A higher order React component to lazy load external javascript files. Scripts are loaded sequentially.

Note: Requires Promise polyfill

Installation

yarn add react-async-load-script

Usage

import scriptLoader from 'react-async-load-script'

scriptLoader([...scripts])(YourComponent)

Example

class D3Chart extends React.Component {
  componentDidUpdate (prevProps) {
    if (
      prevProps.isScriptLoadSucceed !== this.props.isScriptLoadSucceed && 
      this.props.isScriptLoadSucceed
    ) {
      // Initialize d3 chart
      console.log(d3)
    }
  }
  render () {
    return <div className='chart' />
  }
}

export default scriptLoader([
  'https://cdnjs.cloudflare.com/ajax/libs/d3/4.12.0/d3.min.js
])(D3Chart)

Properties

Your component will receive the following props

NameTypeDescription
isScriptLoadedbooleanIndicates if scripts have been loaded
isScriptLoadSuccessbooleanIndicates if all scripts are loaded without error

Test

yarn test

License

MIT

FAQs

Last updated on 28 Jun 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc