This pull request fixes that issue by changing MutableRefObject<undefined | Element> to MutableRefObject<null | Element>, because the ref prop on a div expects a RefObject<null | HTMLDivElement>. Also allows an optional dynamic type element RefType, so that the hook can be used as so:
This allows for the ref to be passed to a <div /> more easily in typescript and allows developers to use other HTMLDivElement-specific properties on the ref.
Part 2: ResizeDetector fixes
I noticed a type discrepancy in the main ResizeDetector component that prevented its use in my strictly-typed application. As you'll see in the changes, I updated the type to that what was actually passed to the child function is what was declared in the props that would be passed.
I tested these changes on my own project and it resolves the typescript issues and appears to behave the same.
Part 1: useResizeDetector fixes
I experienced the same issue as @stefann01: https://github.com/maslianok/react-resize-detector/issues/108#issuecomment-760239999
This pull request fixes that issue by changing
MutableRefObject<undefined | Element>
toMutableRefObject<null | Element>
, because theref
prop on adiv
expects aRefObject<null | HTMLDivElement>
. Also allows an optional dynamic type elementRefType
, so that the hook can be used as so:This allows for the ref to be passed to a
<div />
more easily in typescript and allows developers to use otherHTMLDivElement
-specific properties on the ref.Part 2: ResizeDetector fixes
I noticed a type discrepancy in the main ResizeDetector component that prevented its use in my strictly-typed application. As you'll see in the changes, I updated the type to that what was actually passed to the child function is what was declared in the props that would be passed.
I tested these changes on my own project and it resolves the typescript issues and appears to behave the same.