mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-29 00:10:54 +05:30
#337: fix setState after unmounted warning on AuthFlowRouteContents
This commit is contained in:
parent
9e3926f8e5
commit
1538bcb264
@ -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} />
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user