Created
May 1, 2015 02:24
-
-
Save solomonhawk/2acf050031032f7c7bc9 to your computer and use it in GitHub Desktop.
RefMixin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Ref $elector Mixin | |
*/ | |
export default { | |
$(ref) { | |
return this.refs[ref].getDOMNode() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import RefMixin from 'mixins/refMixin' | |
const Component = React.createClass({ | |
mixins: [ RefMixin ], | |
send() { | |
let name = this.$('name').value | |
let email = this.$('email').value | |
// beep boop | |
this.$('form').reset() | |
}, | |
render() { | |
return ( | |
<div> | |
<form ref="form" onSubmit={ this.send }> | |
<input type="text" ref="name" /> | |
<input type="text" ref="email" /> | |
<button type="submit">Send</button> | |
</form> | |
</div> | |
) | |
} | |
}) | |
export default Component |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment