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