Skip to content

Allow passing DOM elem directly#29

Open
osdiab wants to merge 3 commits intorehooks:masterfrom
osdiab:osdiab/dom-elem
Open

Allow passing DOM elem directly#29
osdiab wants to merge 3 commits intorehooks:masterfrom
osdiab:osdiab/dom-elem

Conversation

@osdiab
Copy link
Copy Markdown

@osdiab osdiab commented Mar 4, 2020

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

Comment thread index.js
function useComponentSize(ref) {
var _useState = useState(getSize(ref ? ref.current : {}))
function useComponentSize(elemOrRef) {
const el = elemOrRef && (
Copy link
Copy Markdown
Author

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

Comment thread index.d.ts
}

export default function useComponentSize<T = any>(ref: React.RefObject<T>): ComponentSize
export default function useComponentSize<T = any>(ref: T | React.RefObject<T>): ComponentSize
Copy link
Copy Markdown
Author

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

Comment thread index.js.flow
}

declare export default function useComponentSize<T>(ref: React.Ref<T>): ComponentSize; No newline at end of file
declare export default function useComponentSize<T>(ref: T | React.Ref<T>): ComponentSize; No newline at end of file
Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refs as effect conditions

1 participant