Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

osdiab
Copy link

@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

function useComponentSize(ref) {
var _useState = useState(getSize(ref ? ref.current : {}))
function useComponentSize(elemOrRef) {
const el = elemOrRef && (
Copy link
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

@@ -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
Copy link
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

declare export default function useComponentSize<T>(ref: T | React.Ref<T>): ComponentSize;
Copy link
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
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