Last active
June 28, 2016 00:55
-
-
Save ericmasiello/0c22dca486bba4fbf2511491d8298fa2 to your computer and use it in GitHub Desktop.
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, { 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