UNPKG

@itwin/core-react

Version:

A react component library of iTwin.js UI general purpose components

42 lines 1.65 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Common */ import * as React from "react"; import { Timer } from "../utils/Timer.js"; /** withTimeout is a React higher-order component that adds timeout support. * @public * @deprecated in 4.15.0. Not used by AppUI. */ export const withTimeout = (Component) => { return class WithTimeout extends React.PureComponent { // eslint-disable-next-line @typescript-eslint/no-deprecated timer = new Timer(0); componentDidMount() { this.timer.setOnExecute(() => this.props.onTimeout && this.props.onTimeout()); this.startTimer(this.props.timeout); } /** @internal */ componentDidUpdate(_prevProps // eslint-disable-line @typescript-eslint/no-deprecated ) { this.startTimer(this.props.timeout); } componentWillUnmount() { this.timer.stop(); } render() { const { timeout, onTimeout, ...props } = this.props; return React.createElement(Component, { ...props, ...this.state }); } startTimer(timeout) { if (this.timer.isRunning) return; this.timer.delay = timeout; this.timer.start(); } }; }; //# sourceMappingURL=withTimeout.js.map