@itwin/core-react
Version:
A react component library of iTwin.js UI general purpose components
36 lines • 1.32 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Utilities
*/
import * as React from "react";
/** Hook that create an interval and clears it when unloaded
* Reference: https://github.com/gaearon/overreacted.io/blob/master/src/pages/making-setinterval-declarative-with-react-hooks/index.md
* @beta
* @deprecated in 4.15.0. Used internally.
*/
export function useInterval(callback, delay) {
const savedCallback = React.useRef(callback);
// Remember the latest function.
React.useEffect(() => {
savedCallback.current = callback;
}, [callback]);
// Set up the interval.
React.useEffect(() => {
function tick() {
savedCallback.current();
}
if (delay !== undefined) {
const id = setInterval(tick, delay);
return () => {
clearInterval(id);
};
}
else {
return undefined;
}
}, [delay]);
}
//# sourceMappingURL=useInterval.js.map