Skip to content

Instantly share code, notes, and snippets.

@solomonhawk
Created May 1, 2015 02:24
Show Gist options
  • Save solomonhawk/2acf050031032f7c7bc9 to your computer and use it in GitHub Desktop.
Save solomonhawk/2acf050031032f7c7bc9 to your computer and use it in GitHub Desktop.
RefMixin
/**
* Ref $elector Mixin
*/
export default {
$(ref) {
return this.refs[ref].getDOMNode()
}
}
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