Skip to content

Instantly share code, notes, and snippets.

@ericmasiello
Last active June 28, 2016 00:55
Show Gist options
  • Save ericmasiello/0c22dca486bba4fbf2511491d8298fa2 to your computer and use it in GitHub Desktop.
Save ericmasiello/0c22dca486bba4fbf2511491d8298fa2 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import $ from 'jquery';
function jqueryAction(context) {
$(document).ready(()=> {
$('.theButton').on('click', ()=> {
$('.theTextarea').val('test value');
var node = context.refs.ta;
ReactTestUtils.Simulate.change(node);
})
});
};
export default class TextComponent extends Component {
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
}
componentWillMount() {
jqueryAction(this); // passing our `this` context to the jQuery function
}
onChange(e) {
console.log(e.target.value);
console.log('refs', this.refs.ta);
this.props.onChange(e.target.value);
}
render() {
return (
<div>
<textarea
ref="ta"
onChange={this.props.onChange ? this.onChange : undefined}
className="theTextarea" />
<br/>
<input type="button" value="jQueryify" className="theButton" />
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment