UNPKG

@itwin/core-react

Version:

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

32 lines (31 loc) 1.04 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"; /** Hook used to store an HTMLElement in state by using ref callback returned from hook. * *Example:* * ``` tsx * const [divElementRef, divElement] = useRefState<HTMLDivElement>(); * const ownerDoc = divElement?.ownerDocument ?? document; * * return ( * <div ref={divElementRef} > * .... * </div> * ); * ``` * } * @internal */ export function useRefState() { const [element, setElement] = React.useState(); const ref = React.useCallback((instance) => { setElement(instance || undefined); }, []); return [ref, element]; } //# sourceMappingURL=useRefState.js.map