@actualwave/use-element-size 中文文档教程
@actualwave/use-element-size
使用 ResizeObserver 监视元素大小变化的 React 钩子,并报告强制组件渲染的更新。 的这个包示例中有两个钩子。
- useResizeObserver(handlerFn, elementRef) -- Calls
handlerFn()
when element size changed with instance of DOMRectReadOnly. - useElementSize(elementRef, reinitInEffect = true) -- Returns element size or null if
elementRef.current
does not contain reference to HTMLElement.reinitInEffect
forces immediate re-render to apply element sizes, expected to have a valid reference at the time of re-render.
@actualwave/use-element-size
React hook that watches for changes in element size using ResizeObserver and reports updates forcing component to render. There are two hooks in this package
- useResizeObserver(handlerFn, elementRef) -- Calls
handlerFn()
when element size changed with instance of DOMRectReadOnly. - useElementSize(elementRef, reinitInEffect = true) -- Returns element size or null if
elementRef.current
does not contain reference to HTMLElement.reinitInEffect
forces immediate re-render to apply element sizes, expected to have a valid reference at the time of re-render.
Example on codesandbox.io.