#337: fix setState after unmounted warning on AuthFlowRouteContents

This commit is contained in:
SleepWalker 2017-06-12 22:14:02 +03:00
parent 9e3926f8e5
commit 1538bcb264

View File

@ -18,14 +18,21 @@ export default class AuthFlowRouteContents extends Component {
component: null
};
_isMounted = false;
componentDidMount() {
this.handleProps(this.props);
this._isMounted = true;
}
componentWillReceiveProps(nextProps: ComponentProps) {
this.handleProps(nextProps);
}
componentWillUnmount() {
this._isMounted = false;
}
render() {
return this.state.component;
}
@ -41,6 +48,10 @@ export default class AuthFlowRouteContents extends Component {
}
onRedirect(path: string) {
if (!this._isMounted) {
return;
}
this.setState({
component: <Redirect to={path} />
});
@ -49,6 +60,10 @@ export default class AuthFlowRouteContents extends Component {
onRouteAllowed(props: ComponentProps) {
const {component: Component} = props;
if (!this._isMounted) {
return;
}
this.setState({
component: <Component {...props.routerProps} />
});