Add optional effect to useResizeObserver
See original GitHub issueWe’ve been using useResizeObserver to track when to trigger a side effect, and so end up with code like this:
const axisRef = useRef();
const cursorRef = useRef();
const { width: axisWidth } = useResizeObserver({ ref: axisRef });
// Reset the axis if the width changes
useEffect(() => {
if (cursorRef.current !== null) {
cursorRef.current.reset();
}
}, [axisWidth]);
It would be convenient if we could simply provide this effect to the resize observer.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
asyarb/use-resize-observer: A small React hook ... - GitHub
Yarn yarn add @asyarb/use-resize-observer # NPM npm i ... Provide an optional callback to perform side effects instead: useResizeObserver({ ref, ...
Read more >UNPKG - @asyarb/use-resize-observer
The CDN for @asyarb/use-resize-observer. ... 74, // Pass an optional callback to perform side effects instead: 75, useResizeObserver(ref, entry => {.
Read more >Resize Observer - W3C
Add this to Document . resizeObservers slot. observe(target, options). Adds target to the list of observed elements.
Read more >@asyarb/use-resize-observer: Docs & Community | Openbase
Hooks - Just pass a ref! Alternative API - Pass an Element and an optional function to handle ResizeObserver callbacks. Typed - Written...
Read more >wordpress/compose | Block Editor Handbook
ifCondition. Higher-order component creator, creating a new component which renders if the given condition is satisfied or with the given optional prop name....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Nice!
You might want to check out this demo @danni : https://codesandbox.io/s/use-resize-observer-throttle-and-debounce-8uvsg