Skip to content

Commit

Permalink
Remove listener on unmount
Browse files Browse the repository at this point in the history
Connects to #14
  • Loading branch information
lloydwatkin committed Oct 12, 2017
1 parent c686fe9 commit f89fb0f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';

export const PLACE_CHANGED = 'place_changed';

export default class ReactGoogleAutocomplete extends React.Component {
static propTypes = {
onPlaceSelected: PropTypes.func,
Expand All @@ -27,7 +29,11 @@ export default class ReactGoogleAutocomplete extends React.Component {

this.autocomplete = new google.maps.places.Autocomplete(this.refs.input, config);

this.autocomplete.addListener('place_changed', this.onSelected.bind(this));
this.autocomplete.addListener(PLACE_CHANGED, this.onSelected.bind(this));
}

componentWillUnmount() {
this.autocomplete.removeListener(PLACE_CHANGED);
}

onSelected() {
Expand Down

0 comments on commit f89fb0f

Please sign in to comment.