Created
July 16, 2015 14:16
-
-
Save eferro/50097e779fdd75175c64 to your computer and use it in GitHub Desktop.
inject state to a react component from outside
This file contains hidden or 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
<html> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> | |
<body> | |
<div id="content"> | |
</div> | |
</body> | |
<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> | |
</div> | |
); | |
} | |
}); | |
var reactComponent = React.render( <HelloComponent />, document.getElementById('content')); | |
var cont = 0; | |
setInterval(function(){ | |
cont = cont + 1; | |
reactComponent.setState({counter: cont}); | |
},1000); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment