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

Change how refs are set #13

Open
james2406 opened this issue Jul 19, 2019 · 3 comments
Open

Change how refs are set #13

james2406 opened this issue Jul 19, 2019 · 3 comments

Comments

@james2406
Copy link

Hey, thanks for creating such a lightweight/performant library! I think this library could improve on its api slightly to make it easier to use in an application using refs. Instead of returning a ref as the first return value, it would be more flexible if it could be passed in as the first argument to useDimensions:

const containerRef = useRef(null);
const dimensions =  useDimensions(containerRef);

This would make it easier to work with other libraries, such as useScrolling:

const containerRef = useRef(null);
const dimensions =  useDimensions(containerRef);
const scrolling = useScrolling(containerRef);

I would be more than happy to make a PR for this change, however, I understand if you wouldn’t want to introduce this change as it would be breaking.

@curran
Copy link

curran commented Jul 19, 2019

I agree that scrolling should be a separate concern. Related to #11

@wmertens
Copy link

Sadly it would mean having to call useRef anyway and ignoring the result because of the rules of hooks. I can't think of a way around that, but I do agree it could be useful.

(Actually, in this case it would be safe to assume that we'd always get the ref and therefore would never call the useRef, but that's a bit hacky)

@KutnerUri
Copy link

this is not hacky, it allows users more freedom to provide the ref than to rely on this hook to provide the ref.

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

No branches or pull requests

4 participants