-
Notifications
You must be signed in to change notification settings - Fork 129
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
Use ref instead of ReactDOM.findDOMNode() #64
Conversation
ReactDOM.findDOMNode() is discouraged, so we use refs instead. This allows us to use this in our server-side render correctly
Really neat solution, thanks @gwu |
@@ -126,6 +126,14 @@ var HammerComponent = React.createClass({ | |||
} | |||
}, this); | |||
|
|||
var self = this; | |||
props.ref = function(domElement) { |
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.
@JedWatson @gwu
cc @silentcloud
This PR will cause two problem:
- break change, see below use case, the children's string ref will be override by Hammer
<Hammer
direction="DIRECTION_HORIZONTAL"
onPanStart={this.onPanStart}
onPan={this.onPan}
onPanEnd={this.onPanEnd}
>
<div className={`${prefixCls}-content`} ref="content">
{children}
</div>
</Hammer>
- cause react warning: https://facebook.github.io/react/warnings/special-props.html
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.
+1 Yes this is breaking ref
for child components
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.
ReactDOM.findDOMNode() is discouraged, so we use refs instead (https://facebook.github.io/react/docs/react-dom.html#finddomnode).
This allows us to use this in our server-side render correctly.