Skip to content

Commit

Permalink
fix(ScriptjsLoader): Fix setState warning (#307)
Browse files Browse the repository at this point in the history
* Make the callback from scriptjs a no-op when unmounting the component.
* Original author: @emilecantin 
* Original commit: 93bfa9b
  • Loading branch information
emilecantin authored and tomchentw committed Oct 4, 2016
1 parent 1c5e933 commit 999fd89
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/async/ScriptjsLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export default class ScriptjsLoader extends Component {
isLoaded: false,
}

setLoaded() {
this.setState({ isLoaded: true });
}

shouldUseNewBehavior() {
const { containerTagName, containerProps } = this.props.googleMapElement.props;
return (
Expand Down Expand Up @@ -84,7 +88,7 @@ See https://github.com/tomchentw/react-google-maps/pull/157 for more details.`
const { protocol, hostname, port, pathname, query } = this.props;
const urlObj = { protocol, hostname, port, pathname, query };
const url = makeUrl(urlObj);
scriptjs(url, () => this.setState({ isLoaded: true }));
scriptjs(url, () => this.setLoaded());
}

componentWillReceiveProps(nextProps) {
Expand All @@ -100,6 +104,12 @@ Changed props: %s`,
}
}

componentWillUnmount() {
// Set this to a no-op so we avoid using setState when the
// component is unmounted;
this.setLoaded = () => {};
}

render() {
if (this.state.isLoaded) {
if (this.shouldUseNewBehavior()) {
Expand Down

0 comments on commit 999fd89

Please sign in to comment.