#22: fix set state warnings in Form.js

This commit is contained in:
SleepWalker 2018-05-07 22:23:26 +03:00
parent c454c58d5c
commit 64cb197756

View File

@ -38,10 +38,14 @@ export default class Form extends Component<Props, State> {
formEl: ?HTMLFormElement; formEl: ?HTMLFormElement;
componentWillMount() { mounted = false;
componentDidMount() {
if (this.props.form) { if (this.props.form) {
this.props.form.addLoadingListener(this.onLoading); this.props.form.addLoadingListener(this.onLoading);
} }
this.mounted = true;
} }
componentWillReceiveProps(nextProps: Props) { componentWillReceiveProps(nextProps: Props) {
@ -73,6 +77,8 @@ export default class Form extends Component<Props, State> {
if (this.props.form) { if (this.props.form) {
this.props.form.removeLoadingListener(this.onLoading); this.props.form.removeLoadingListener(this.onLoading);
} }
this.mounted = false;
} }
render() { render() {
@ -119,7 +125,9 @@ export default class Form extends Component<Props, State> {
result.catch((errors: {[key: string]: string}) => { result.catch((errors: {[key: string]: string}) => {
this.setErrors(errors); this.setErrors(errors);
}).finally(() => this.setState({isLoading: false})); }).finally(() =>
this.mounted && this.setState({isLoading: false})
);
} }
} else { } else {
const invalidEls = form.querySelectorAll(':invalid'); const invalidEls = form.querySelectorAll(':invalid');