ZeeCoder / use-resize-observer

A React hook that allows you to use a ResizeObserver to measure an element's size.
MIT License
651 stars 42 forks source link

useResizeDetector resize method is not triggering in v7.0.1 #82

Closed opr1cob closed 3 years ago

opr1cob commented 3 years ago

useResizeDetector({ ref: communicationref, onResize: debounce(handlecommunicationResize, delay, { maxWait: 1000 }), })

function handlecommunicationResize({ height }) { console.log(height); }

its working perfectly in v7.0.0

ZeeCoder commented 3 years ago

Interesting. Can you also post the code for debounce and delay?

Or better yet, could you create a codesandbox, reproducing the issue?

For the time being, you can also try and use this solution for a debounced hook instead: https://codesandbox.io/s/use-resize-observer-throttle-and-debounce-8uvsg?file=/src/useDebouncedResizeObserver.js

opr1cob commented 3 years ago

without debounce and delay also resize callback is not triggering in v7.0.1 useResizeDetector({ ref: communicationref, onResize: ({ width, height }) => { console.log(height); }, })

ZeeCoder commented 3 years ago

That should work for sure, and I have tests covering it. I really can't look into the issue without having a way to reproduce it.

ZeeCoder commented 3 years ago

One thing I'd also try from the top of my head is using the callback ref returned by the hook, instead of passing in an object ref, so:

const { ref } = useResizeDetector({
  onResize: ({ width, height }) => {
    console.log(height);
  },
});

<div ref={ref} />

This would work better if you mount the observed component with a delay for example.

opr1cob commented 3 years ago

I have tried the suggested way to capture the callback but no luck , its not working in v7.0.1

ZeeCoder commented 3 years ago

Sorry I really am unable to help unless you provide me a reproduction of the issue through either a repo, codesandbox or something similar.

ZeeCoder commented 3 years ago

I'm closing this for now, but feel free to reopen if you have a reproduction.