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

Avoid swallowing children's ref property, if it's set. Fixes #83 #87

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

Conversation

raulrene
Copy link

No description provided.

@@ -149,7 +149,10 @@ var HammerComponent = function (_React$Component) {

var self = this;
props.ref = function (domElement) {
if (self.props.ref) {
if (self.props.children && self.props.children.ref) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, whether this is the best solution because ref is a special prop.
Actually, the problem is not only that the child's ref is swallowed but also that self.props.ref will always return undefined (and I would expect the same for self.props.children.ref). A ref callback added to the <Hammer> component will still be executed (but independently, i.e. it will never be called here and if it did, it would be executed twice).

Maybe it is possible to add another prop to the official interface of the Hammer component that will be executed here. Something like

<Hammer
    onPan={onPanHandler}
    refCallback={domElement => myRef = domElement /* domElement will be the child, i.e. the div below */}
>
    <div>something cool</div>
</Hammer>

and then

props.ref = function(domElement) {
    if (self.props.refCallback) {
        self.props.refCallback(domElement);
    }
    self.domElement = domElement;
}

This would still swallow the child's ref but if it's documented that refCallback of the Hammer component will get passed the actual child element, one can just place the child's ref there and it will work as expected. This would also avoid trying to access the ref prop directly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second using a unique prop name such as refCallback as to avoid conflict with React special props.

@ArtemBernatskyy
Copy link

Guys, so what ?

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.

5 participants