Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Latest commit

 

History

History

react-script-loader

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

react-script-loader

Build Status

React script loader

Installation

npm install --save @wapps/react-script-loader

How to use

import React, { Component } from 'react';
import withScriptLoader from '@wapps/react-script-loader';

class GoogleMaps extends Component {
  ...

  componentDidMount() {
    const { hasScriptsLoaded, hasScriptsLoadedSuccessfully } = this.props;
    if (hasScriptsLoaded && hasScriptsLoadedSuccessfully) {
      this.setState({
        googleMaps: window.google.maps,
      });
    }
  }

  componentDidUpdate(prevProps) {
    const { hasScriptsLoaded, hasScriptsLoadedSuccessfully } = this.props;
    if (hasScriptsLoaded && !prevProps.hasScriptsLoaded) {
      if (hasScriptsLoadedSuccessfully) {
        this.setState({
          googleMaps: window.google.maps,
        });
      }
    }
  }

  ...
}

export default withScriptLoader({
  src: 'https://maps.googleapis.com/maps/api/js...'
})(GoogleMaps)

License

MIT