Skip to content

Commit 6d4d442

Browse files
authored
Merge pull request #173 from sonaye/patch-1
Add React 16 to peerDependencies
2 parents 0137a67 + 4b3cf70 commit 6d4d442

File tree

13 files changed

+467
-592
lines changed

13 files changed

+467
-592
lines changed

README.md

Lines changed: 77 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<p align="center">
32
<img src="resources/readme/fullstackreact-google-maps-tutorial.png" alt="Fullstack React Google Maps Tutorial" />
43
</p>
@@ -49,6 +48,7 @@ If you want to add a loading container _other than the default_ loading containe
4948
const LoadingContainer = (props) => (
5049
<div>Fancy loading container!</div>
5150
)
51+
5252
export default GoogleApiWrapper({
5353
apiKey: (YOUR_GOOGLE_API_KEY_GOES_HERE),
5454
LoadingContainer: LoadingContainer
@@ -61,7 +61,7 @@ export default GoogleApiWrapper({
6161
import {Map, InfoWindow, Marker, GoogleApiWrapper} from 'google-maps-react';
6262

6363
export class MapContainer extends Component {
64-
render() {
64+
render() {
6565
return (
6666
<Map google={this.props.google} zoom={14}>
6767

@@ -138,58 +138,55 @@ The `<Map />` component handles events out of the box. All event handlers are op
138138
When the `<Map />` instance has been loaded and is ready on the page, it will call the `onReady` prop, if given. The `onReady` prop is useful for fetching places or using the autocomplete API for places.
139139

140140
```javascript
141-
React.createClass({
142-
fetchPlaces: function(mapProps, map) {
143-
const {google} = mapProps;
144-
const service = new google.maps.places.PlacesService(map);
145-
// ...
146-
},
147-
render: function() {
148-
return (
149-
<Map google={this.props.google}
150-
onReady={this.fetchPlaces}
151-
visible={false}>
152-
<Listing places={this.state.places} />
153-
</Map>
154-
)
155-
}
156-
});
141+
fetchPlaces(mapProps, map) {
142+
const {google} = mapProps;
143+
const service = new google.maps.places.PlacesService(map);
144+
// ...
145+
}
146+
147+
render() {
148+
return (
149+
<Map google={this.props.google}
150+
onReady={this.fetchPlaces}
151+
visible={false}>
152+
<Listing places={this.state.places} />
153+
</Map>
154+
)
155+
}
157156
```
158157

159158
#### onClick
160159

161160
To listen for clicks on the `<Map />` component, pass the `onClick` prop:
162161

163162
```javascript
164-
React.createClass({
165-
mapClicked: function(mapProps, map, clickEvent) {
166-
// ...
167-
},
168-
render: function() {
169-
return (
170-
<Map google={this.props.google}
171-
onClick={this.mapClicked} />
172-
)
173-
}
174-
});
163+
mapClicked(mapProps, map, clickEvent) {
164+
// ...
165+
}
166+
167+
render() {
168+
return (
169+
<Map google={this.props.google}
170+
onClick={this.mapClicked} />
171+
)
172+
}
175173
```
176174

177175
#### onDragend
178176

179177
When our user changes the map center by dragging the Map around, we can get a callback after the event is fired with the `onDragend` prop:
180178

181179
```javascript
182-
React.createClass({
183-
centerMoved: function(mapProps, map) {
184-
// ...
185-
},
186-
render: function() {
187-
return (
188-
<Map google={this.props.google}
189-
onDragend={this.centerMoved} />
190-
)
191-
}
192-
});
180+
centerMoved(mapProps, map) {
181+
// ...
182+
}
183+
184+
render() {
185+
return (
186+
<Map google={this.props.google}
187+
onDragend={this.centerMoved} />
188+
)
189+
}
193190
```
194191

195192
### Visibility
@@ -256,51 +253,52 @@ The `<Marker />` component listens for events, similar to the `<Map />` componen
256253
You can listen for an `onClick` event with the (appropriately named) `onClick` prop.
257254

258255
```javascript
259-
const WithMarkers = React.createClass({
260-
onMarkerClick: function(props, marker, e) {
261-
},
262-
render: function() [
263-
return (
264-
<Map google={this.props.google}>
265-
<Marker onClick={this.onMarkerClick}
266-
name={'Current location'} />
267-
</Map>
268-
)
269-
]
270-
});
256+
onMarkerClick(props, marker, e) {
257+
// ..
258+
}
259+
260+
render() {
261+
return (
262+
<Map google={this.props.google}>
263+
<Marker onClick={this.onMarkerClick}
264+
name={'Current location'} />
265+
</Map>
266+
)
267+
}
271268
```
272269

273270
#### mouseover
274271

275272
You can also pass a callback when the user mouses over a `<Marker />` instance by passing the `onMouseover` callback:
276273

277274
```javascript
278-
const Container = React.createClass({
279-
onMouseoverMarker: function(props, marker, e) {
280-
},
281-
render: function() [
282-
return (
283-
<Map google={this.props.google}>
284-
<Marker onMouseover={this.onMouseoverMarker}
285-
name={'Current location'} />
286-
</Map>
287-
)
288-
]
289-
});
275+
onMouseoverMarker(props, marker, e) {
276+
// ..
277+
}
278+
279+
render() {
280+
return (
281+
<Map google={this.props.google}>
282+
<Marker onMouseover={this.onMouseoverMarker}
283+
name={'Current location'} />
284+
</Map>
285+
)
286+
}
290287
```
291288

292289
### Polygon
293290

294291
To place a polygon on the Map, set `<Polygon />` as child of Map component.
295292

296293
```javascript
297-
render: function() {
298-
var triangleCoords = [
294+
render() {
295+
const triangleCoords = [
299296
{lat: 25.774, lng: -80.190},
300297
{lat: 18.466, lng: -66.118},
301298
{lat: 32.321, lng: -64.757},
302299
{lat: 25.774, lng: -80.190}
303300
];
301+
304302
return(
305303
<Map google={this.props.google}
306304
style={{width: '100%', height: '100%', position: 'relative'}}
@@ -327,13 +325,14 @@ The `<Polygon />` component listens to `onClick`, `onMouseover` and `onMouseout`
327325
To place a polyline on the Map, set `<Polyline />` as child of Map component.
328326

329327
```javascript
330-
render: function() {
331-
var triangleCoords = [
328+
render() {
329+
const triangleCoords = [
332330
{lat: 25.774, lng: -80.190},
333331
{lat: 18.466, lng: -66.118},
334332
{lat: 32.321, lng: -64.757},
335333
{lat: 25.774, lng: -80.190}
336334
];
335+
337336
return(
338337
<Map google={this.props.google}
339338
style={{width: '100%', height: '100%', position: 'relative'}}
@@ -367,37 +366,29 @@ You can use a `position` prop or connect the `<InfoWindow />` component directly
367366
```javascript
368367
//note: code formatted for ES6 here
369368
export class MapContainer extends Component {
370-
constructor(props) {
371-
super(props);
372-
this.state = {
373-
showingInfoWindow: false,
374-
activeMarker: {},
375-
selectedPlace: {},
376-
}
369+
state = {
370+
showingInfoWindow: false,
371+
activeMarker: {},
372+
selectedPlace: {},
373+
};
377374

378-
// binding this to event-handler functions
379-
this.onMarkerClick = this.onMarkerClick.bind(this);
380-
this.onMapClicked = this.onMapClicked.bind(this);
381-
}
382-
383-
onMarkerClick: function(props, marker, e) {
375+
onMarkerClick = (props, marker, e) =>
384376
this.setState({
385377
selectedPlace: props,
386378
activeMarker: marker,
387379
showingInfoWindow: true
388380
});
389-
},
390381

391-
onMapClicked: function(props) {
382+
onMapClicked = (props) => {
392383
if (this.state.showingInfoWindow) {
393384
this.setState({
394385
showingInfoWindow: false,
395386
activeMarker: null
396387
})
397388
}
398-
},
389+
};
399390

400-
render: function() {
391+
render() {
401392
return (
402393
<Map google={this.props.google}
403394
onClick={this.onMapClicked}>
@@ -414,7 +405,7 @@ export class MapContainer extends Component {
414405
</Map>
415406
)
416407
}
417-
});
408+
}
418409
```
419410

420411
### Events

examples/Container.js

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,83 @@
1-
import React from 'react';
2-
import PropTypes from 'prop-types';
3-
import ReactDOM from 'react-dom';
4-
import {Link} from 'react-router';
5-
import GitHubForkRibbon from 'react-github-fork-ribbon';
1+
import React, { Component } from 'react';
62

7-
let GoogleApiWrapper;
8-
if (__IS_DEV__) {
9-
GoogleApiWrapper = require('../src/index').GoogleApiWrapper;
10-
} else {
11-
GoogleApiWrapper = require('../dist').GoogleApiWrapper;
12-
}
3+
import GitHubForkRibbon from 'react-github-fork-ribbon';
4+
import PropTypes from 'prop-types';
5+
import { Link } from 'react-router';
136

147
import styles from './styles.module.css';
158

16-
export const Container = React.createClass({
17-
propTypes: {
9+
const GoogleApiWrapper = __IS_DEV__
10+
? require('../src/index').GoogleApiWrapper
11+
: require('../dist').GoogleApiWrapper;
12+
13+
class Container extends Component {
14+
static propTypes = {
1815
children: PropTypes.element.isRequired
19-
},
16+
};
2017

21-
contextTypes: {
18+
static contextTypes = {
2219
router: PropTypes.object
23-
},
20+
};
21+
22+
renderChildren = () => {
23+
const { children } = this.props;
2424

25-
renderChildren: function() {
26-
const {children} = this.props;
2725
if (!children) return;
2826

2927
const sharedProps = {
3028
google: this.props.google,
3129
loaded: this.props.loaded
3230
};
33-
return React.Children.map(children, c => {
34-
return React.cloneElement(c, sharedProps, {});
35-
});
36-
},
3731

38-
render: function() {
39-
const {routeMap, routeDef} = this.props;
40-
const {router} = this.context;
32+
return React.Children.map(children, child =>
33+
React.cloneElement(child, sharedProps, {})
34+
);
35+
};
36+
37+
render() {
38+
const { routeMap, routeDef } = this.props;
4139

42-
const c = this.renderChildren();
4340
return (
4441
<div className={styles.container}>
4542
<GitHubForkRibbon
4643
href="//github.com/fullstackreact/google-maps-react"
47-
target="_blank"
4844
position="right"
49-
>
45+
target="_blank">
5046
Fork me on GitHub
5147
</GitHubForkRibbon>
48+
5249
<div className={styles.wrapper}>
5350
<div className={styles.list}>
5451
<ul>
55-
{Object.keys(routeMap).map(key => {
56-
return (
57-
<Link to={key} activeClassName={styles.active} key={key}>
58-
<li>{routeMap[key].name}</li>
59-
</Link>
60-
);
61-
})}
52+
{Object.keys(routeMap).map(key => (
53+
<Link activeClassName={styles.active} key={key} to={key}>
54+
<li>{routeMap[key].name}</li>
55+
</Link>
56+
))}
6257
</ul>
6358
</div>
59+
6460
<div className={styles.content}>
6561
<div className={styles.header}>
6662
<h1>{routeDef && routeDef.name} Example</h1>
63+
6764
<h2>
6865
<a href="https://github.com/fullstackreact/google-maps-react/blob/master/README.md">
6966
Readme
7067
</a>
7168
</h2>
7269
</div>
73-
{c}
70+
71+
{this.renderChildren()}
7472
</div>
7573
</div>
7674
</div>
7775
);
7876
}
79-
});
77+
}
78+
79+
const Loading = () => <div>Fancy loading container</div>;
8080

81-
const Loading = props => <div>Fancy loading container</div>;
8281
export default GoogleApiWrapper({
8382
apiKey: __GAPI_KEY__,
8483
libraries: ['places', 'visualization'],

0 commit comments

Comments
 (0)