-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow passing DOM elem directly #29
base: master
Are you sure you want to change the base?
Conversation
function useComponentSize(ref) { | ||
var _useState = useState(getSize(ref ? ref.current : {})) | ||
function useComponentSize(elemOrRef) { | ||
const el = elemOrRef && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this statement altogether, and rename elemOrRef
to el
to make this a breaking change that drops support for RefObject
inputs.
This would be better to make it clearer to users that passing in a RefObject
is asking for trouble since it won't trigger a re-render
@@ -3,4 +3,4 @@ interface ComponentSize { | |||
height: number | |||
} | |||
|
|||
export default function useComponentSize<T = any>(ref: React.RefObject<T>): ComponentSize | |||
export default function useComponentSize<T = any>(ref: T | React.RefObject<T>): ComponentSize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the React.RefObject<T>
type if we make this a breaking change
declare export default function useComponentSize<T>(ref: T | React.Ref<T>): ComponentSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the React.Ref<T>
type if we make this a breaking change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separately, idk where the flow types are since idk how flow works, but is this supposed to be RefObject
? shrug
Closes #17 and retained support for
Ref
instance even though it's a red herring - won't work properly for the reasons explained in the issue