From 64cb197756d1afa9af429e98d57d349f5b771276 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Mon, 7 May 2018 22:23:26 +0300 Subject: [PATCH] #22: fix set state warnings in Form.js --- src/components/ui/form/Form.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/ui/form/Form.js b/src/components/ui/form/Form.js index 6a97feb..a7ecca5 100644 --- a/src/components/ui/form/Form.js +++ b/src/components/ui/form/Form.js @@ -38,10 +38,14 @@ export default class Form extends Component { formEl: ?HTMLFormElement; - componentWillMount() { + mounted = false; + + componentDidMount() { if (this.props.form) { this.props.form.addLoadingListener(this.onLoading); } + + this.mounted = true; } componentWillReceiveProps(nextProps: Props) { @@ -73,6 +77,8 @@ export default class Form extends Component { if (this.props.form) { this.props.form.removeLoadingListener(this.onLoading); } + + this.mounted = false; } render() { @@ -119,7 +125,9 @@ export default class Form extends Component { result.catch((errors: {[key: string]: string}) => { this.setErrors(errors); - }).finally(() => this.setState({isLoading: false})); + }).finally(() => + this.mounted && this.setState({isLoading: false}) + ); } } else { const invalidEls = form.querySelectorAll(':invalid');