Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(async/withScriptjs): provide HOC for loading
googleMapURL
with…
… `scriptjs` * `withScriptjs` requires a prop: `googleMapURL` * `withScriptjs` requires a prop: `loadingElement` BREAKING CHANGE: Apply `withScriptjs` HOC before `withGoogleMaps` HOC. Before: ```js <ScriptjsLoader hostname={"maps.googleapis.com"} pathname={"/maps/api/js"} query={{v: `3.${ AsyncGettingStarted.version }`, libraries: "geometry,drawing,places"}} loadingElement={ <div {...this.props} style={{ height: "100%" }}> <FaSpinner /> </div> } containerElement={ <div {...this.props} style={{ height: "100%" }} /> } googleMapElement={ <GoogleMap ref={googleMap => { googleMap && console.log(`Zoom: ${ googleMap.getZoom() }`); }} defaultZoom={3} defaultCenter={{lat: -25.363882, lng: 131.044922}} onClick={::this.handleMapClick} > <Marker {...this.state.marker} onRightclick={this.handleMarkerRightclick} /> </GoogleMap> } /> ``` After: ```js // Wrap all `react-google-maps` components with `withGoogleMap` HOC // then wraps it into `withScriptjs` HOC // It loads Google Maps JavaScript API v3 for you asynchronously. // Name the component AsyncGettingStartedExampleGoogleMap const AsyncGettingStartedExampleGoogleMap = withScriptjs( withGoogleMap( props => ( <GoogleMap ref={props.onMapLoad} defaultZoom={3} defaultCenter={{ lat: -25.363882, lng: 131.044922 }} onClick={props.onMapClick} > {props.markers.map(marker => ( <Marker {...marker} onRightClick={() => props.onMarkerRightClick(marker)} /> ))} </GoogleMap> ) ); // Then, render it: render( <GettingStartedGoogleMap googleMapURL="https://maps.googleapis.com/maps/api/js?v=3.exp" loadingElement={ <div style={{ height: `100%` }}> <FaSpinner style={{ display: `block`, width: `80px`, height: `80px`, margin: `150px auto`, animation: `fa-spin 2s infinite linear`, }} /> </div> } containerElement={ <div style={{ height: `100%` }} /> } mapElement={ <div style={{ height: `100%` }} /> } onMapLoad={_.noop} onMapClick={_.noop} markers={markers} onMarkerRightClick={_.noop} />, document.getElementById('root') ); ```
- Loading branch information
14d9273
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in the commit message. It should be:
See: a144259