UNPKG

@itwin/core-react

Version:

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

49 lines 1.46 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 Utilities */ import * as React from "react"; /** Callback ref type guard. */ function isRefCallback(ref) { return typeof ref === "function"; } /** Hook used to combine multiple refs. * @internal */ export function useRefs(...refs) { return React.useCallback((instance) => { for (const ref of refs) { if (ref) { if (isRefCallback(ref)) { ref(instance); } else { ref.current = instance; } } } }, // eslint-disable-next-line react-hooks/exhaustive-deps [...refs]); } /** Used to combine multiple refs for a class component. * @internal */ export function mergeRefs(...refs) { return (instance) => { for (const ref of refs) { if (ref) { if (isRefCallback(ref)) { ref(instance); } else { ref.current = instance; } } } }; } //# sourceMappingURL=useRefs.js.map