-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
ReactDOM.findDOMNode() is discouraged, so we use refs instead. This allows us to use this in our server-side render correctly
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,7 +99,7 @@ var HammerComponent = React.createClass({ | |
}, | ||
|
||
componentDidMount: function () { | ||
this.hammer = new Hammer(ReactDOM.findDOMNode(this)); | ||
this.hammer = new Hammer(this.domElement); | ||
updateHammer(this.hammer, this.props); | ||
}, | ||
|
||
|
@@ -126,6 +126,14 @@ var HammerComponent = React.createClass({ | |
} | ||
}, this); | ||
|
||
var self = this; | ||
props.ref = function(domElement) { | ||
if (self.props.ref) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
paranoidjk
|
||
self.props.ref(domElement); | ||
} | ||
self.domElement = domElement; | ||
}; | ||
|
||
// Reuse the child provided | ||
// This makes it flexible to use whatever element is wanted (div, ul, etc) | ||
return React.cloneElement(React.Children.only(this.props.children), props); | ||
|
1 comment
on commit 7f01c51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit has broken the ref
callback usage in the children passed to <Hammer>
:
- Hammer breaks ref in children #93
- Warning: Hammer:
ref
is not a prop. Trying to access it will result inundefined
being returned. If you need to access the same value within the child component, you should pass it as a different prop. #84
Thanks.
@silentcloud 是不是这里影响了你给 Hammer 设 ref ?