Cancel update call is component will be unmounted

This commit is contained in:
Rene Pfeuffer
2019-12-17 12:14:43 +01:00
parent 5dc7bdc28e
commit c72bcb04c1

View File

@@ -25,6 +25,10 @@ type Props = WithTranslation & {
match: any; match: any;
}; };
type State = {
stoppableUpdateHandler?: number;
}
const FixedWidthTh = styled.th` const FixedWidthTh = styled.th`
width: 16px; width: 16px;
`; `;
@@ -41,11 +45,26 @@ export function findParent(path: string) {
return ""; return "";
} }
class FileTree extends React.Component<Props> { class FileTree extends React.Component<Props, State> {
componentDidUpdate(prevProps: Readonly<Props>, prevState: Readonly<{}>, snapshot?: any): void {
const { tree, updateSources } = this.props; constructor(props: Props) {
super(props);
this.state = {};
}
componentDidUpdate(prevProps: Readonly<Props>, prevState: Readonly<State>): void {
if (prevState.stoppableUpdateHandler === this.state.stoppableUpdateHandler) {
const {tree, updateSources} = this.props;
if (tree?._embedded?.children && tree._embedded.children.find(c => c.partialResult)) { if (tree?._embedded?.children && tree._embedded.children.find(c => c.partialResult)) {
setTimeout(updateSources, 3000); const stoppableUpdateHandler = setTimeout(updateSources, 3000);
this.setState({stoppableUpdateHandler: stoppableUpdateHandler});
}
}
}
componentWillUnmount(): void {
if (this.state.stoppableUpdateHandler) {
clearTimeout(this.state.stoppableUpdateHandler);
} }
} }