Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(withGoogleMap): provide HOC for initialize
google.maps.Map
ins…
…tance * `withGoogleMap` requires a prop: `containerElement` * `withGoogleMap` requires a prop: `mapElement` BREAKING CHANGE: Wrap all `react-google-maps` components inside `withGoogleMap` HOC. Before: ```js // v5.0.0 <GoogleMapLoader containerElement={ <div {...this.props} style={{ height: "100%", }} /> } googleMapElement={ <GoogleMap ref={(map) => console.log(map)} defaultZoom={3} defaultCenter={{lat: -25.363882, lng: 131.044922}} onClick={::this.handleMapClick}> {this.state.markers.map((marker, index) => { return ( <Marker {...marker} onRightclick={this.handleMarkerRightclick.bind(this, index)} /> ); })} </GoogleMap> } /> // or v4.0.0 <GoogleMap containerProps={{ ...this.props, style: { height: "100%", }, }} ref="map" defaultZoom={3} defaultCenter={{lat: -25.363882, lng: 131.044922}} onClick={::this.handleMapClick}> {this.state.markers.map((marker, index) => { return ( <Marker {...marker} onRightclick={this.handleMarkerRightclick.bind(this, index)} /> ); })} </GoogleMap> ``` After: ```js // Wrap all `react-google-maps` components with `withGoogleMap` HOC // and name it GettingStartedGoogleMap const GettingStartedGoogleMap = withGoogleMap(props => ( <GoogleMap ref={props.onMapLoad} defaultZoom={3} defaultCenter={{ lat: -25.363882, lng: 131.044922 }} onClick={props.onMapClick} > {props.markers.map((marker, index) => ( <Marker {...marker} onRightClick={() => props.onMarkerRightClick(index)} /> ))} </GoogleMap> )); // Then, render it: render( <GettingStartedGoogleMap containerElement={ <div style={{ height: `100%` }} /> } mapElement={ <div style={{ height: `100%` }} /> } onMapLoad={_.noop} onMapClick={_.noop} markers={markers} onMarkerRightClick={_.noop} />, document.getElementById('root') ); ```
- Loading branch information