Skip to content

Instantly share code, notes, and snippets.

Created Jul 16, 2015
What would you like to do?
inject state to a react component from outside
<script src=""></script>
<script src=""></script>
<script src=""></script>
<div id="content">
<script type="text/jsx">
var HelloComponent = React.createClass({
getInitialState: function () {
return {counter: 0};
render: function() {
return (
<div className="helloCoponent">
<h1>Counter { this.state.counter } </h1>
var reactComponent = React.render( <HelloComponent />, document.getElementById('content'));
var cont = 0;
cont = cont + 1;
reactComponent.setState({counter: cont});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment