clear setinterval after unmounting component
This commit is contained in:
parent
1ed3c1444d
commit
f0be3013ac
1 changed files with 13 additions and 3 deletions
|
@ -9,6 +9,7 @@ interface IBody {
|
||||||
|
|
||||||
interface IBodyState {
|
interface IBodyState {
|
||||||
currentBuild: any;
|
currentBuild: any;
|
||||||
|
intervalId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,11 +27,19 @@ class body extends React.Component<IBody, IBodyState> {
|
||||||
constructor(props){
|
constructor(props){
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
currentBuild: []
|
currentBuild: [],
|
||||||
|
intervalId: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
setInterval(() => this.getBuilds(), 1000);
|
let intervalId: number = setInterval(() => this.getBuilds(), 1000);
|
||||||
|
this.setState({
|
||||||
|
currentBuild: this.state.currentBuild,
|
||||||
|
intervalId: intervalId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
comoponentDidUnmount() {
|
||||||
|
clearInterval(this.state.intervalId);
|
||||||
}
|
}
|
||||||
getBuilds() {
|
getBuilds() {
|
||||||
let api: any = this.props.api;
|
let api: any = this.props.api;
|
||||||
|
@ -56,7 +65,8 @@ class body extends React.Component<IBody, IBodyState> {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
currentBuild: builds
|
currentBuild: builds,
|
||||||
|
intervalId: this.state.intervalId
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue