UNPKG

@awsui/components-react

Version:

AWS UI is a collection of [React](https://reactjs.org/) components that help create intuitive, responsive, and accessible user experiences for web applications. It is developed by Amazon Web Services (AWS). This work is available under the terms of the [A

14 lines (13 loc) 623 B
import { useRef, useCallback } from 'react'; import { useResizeObserver } from './use-resize-observer'; export function useContainerQuery(mapFn, deps) { if (deps === void 0) { deps = []; } var elementRef = useRef(null); var refFn = useCallback(function () { return elementRef.current; }, []); var memoizedMapFn = useCallback(function (entry, prevState) { var contentBox = entry.contentBoxSize[0]; return mapFn({ width: contentBox.inlineSize, height: contentBox.blockSize }, prevState); }, deps); var state = useResizeObserver(refFn, memoizedMapFn); return [state, elementRef]; }