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

ref doesn't work on <swipeable> #77

Closed
DrBoria opened this issue Jul 4, 2017 · 4 comments
Closed

ref doesn't work on <swipeable> #77

DrBoria opened this issue Jul 4, 2017 · 4 comments
Assignees

Comments

@DrBoria
Copy link

DrBoria commented Jul 4, 2017

Can't use ref on swipeable container. Ref links not to dom node, but on swipeable component.

@hartzis
Copy link
Collaborator

hartzis commented Jul 5, 2017

@DrBoria nice find and thank you for creating an issue. I'm surprised this is the first time someone has mentioned and asked for ref's. This is definitely doable!

We have a few options:

Essentially there is no way currently to just do <Swipeable ref={(el) => this.el = el} >, it appears as though we need to create prop that takes a callback that provides the ref element.

We just need to decide on what to name it, currently leaning towards innerRef. Thoughts?

Great reference to follow the real issue with ref's and HOC's - facebook/react#4213

@hartzis hartzis self-assigned this Jul 5, 2017
@DrBoria
Copy link
Author

DrBoria commented Jul 19, 2017

Cool thanks)
Nice work!

@zeus2198
Copy link

I was using the useSwipeable() method, and the ref was working if I mentioned the ref prop after the handlers spread in the component but it stopped detecting swipe in touch devices. I got everything to work normally with this workaround:

const handlers = useSwipeable({ ... });
const myRef = React.useRef();

<div {...handlers} ref={(t) => {
  handlers.ref(t); // calling halders ref for touch devices
  myRef.current = t; // setting our ref
}}>

Note: The ref prop has to be mentioned after {...handlers} else this won't work.

@hartzis
Copy link
Collaborator

hartzis commented Sep 14, 2020

@xxxzeus nice! that's the same approach i tried to communicate here too.

We'll try to make this a bit more obvious and document it well in v6.

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

3 participants