0.0.7 • Published 5 years ago

@wapps/react-script-loader v0.0.7

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

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

0.0.7

5 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago