React Equivalent of ng-click
Code sample to demonstrating the equivalent of an Angular's ng-click directive in React.
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://fb.me/react-with-addons-0.14.0.js"></script>
<script src="https://fb.me/react-dom-0.14.0.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.css">
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<div id="react-content"></div>
JavaScript 1.7
var ClickDemoComponent = React.createClass({
getInitialState: function() {
return { clickCount: 0 }
},
handleClick: function() {
this.setState({clickCount: this.state.clickCount+1});
},
render: function() {
return (
<button onClick={this.handleClick}>
Ive been clicked time
</button>
);
}
});
ReactDOM.render(<ClickDemoComponent />, document.getElementById('react-content'));