UNPKG

@itwin/core-react

Version:

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

20 lines 934 B
/*--------------------------------------------------------------------------------------------- * 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"; /** Returns callback ref that is easy to setup and cleanup (API wise similar to React.useEffect). * @internal */ export function useRefEffect(callback, deps) { const cleanup = React.useRef(null); return React.useCallback((instance) => { cleanup.current && cleanup.current(); const newCleanup = callback(instance); cleanup.current = !newCleanup ? null : newCleanup; }, deps); // eslint-disable-line react-hooks/exhaustive-deps } //# sourceMappingURL=useRefEffect.js.map