Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ScriptjsLoader): Fix setState warning #307

Merged
merged 1 commit into from
Oct 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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