UNPKG

google-react-maps

Version:

A more powerfully custom version of the Google Maps Javascript API built for React. Multiple Datalayer support. GEOJSON Enabled.

50 lines (37 loc) 1.99 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMapsApi = undefined; var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); exports.default = useGoogleMaps; var _react = require('react'); var _react2 = _interopRequireDefault(_react); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var mapsapi = require('google-maps-api'); var getMapsApi = exports.getMapsApi = function getMapsApi(options, callback) { if (!options.libraries) console.warn('Please provide a list of libraries to include in the maps api.'); if (!options.apiKey) throw new Error('Api key must be provided.'); mapsapi(options.apiKey, options.libraries || [])().then(function (api) { callback(api); }).catch(function (error) { return console.error(error); }); }; function useGoogleMaps(_ref) { var apiKey = _ref.apiKey, libaries = _ref.libaries; var _React$useState = _react2.default.useState(null), _React$useState2 = _slicedToArray(_React$useState, 2), maps = _React$useState2[0], setMaps = _React$useState2[1]; _react2.default.useEffect(function () { if (apiKey) { getMapsApi({ apiKey: apiKey, libraries: libraries }, function (maps) { return setMaps(maps); }); } }, [apiKey]); return maps; } //# sourceMappingURL=useGoogleMaps.js.map