React ES6 Counter

React counter build with es6

by Lio Fleishman

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://npmcdn.com/react@latest/dist/react-with-addons.js"></script>
<script src="https://npmcdn.com/react-dom@latest/dist/react-dom.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>

<div id="container">
  <!-- This element's contents will be replaced with your component. -->
</div>

JavaScript 1.7

class Timer extends React.Component {
    constructor(props) {
      super(props)
      this.state = {
        secondsElapsed: 0
      };
      this.tick = this.tick.bind(this);
    }

    tick() {
      this.setState({
        secondsElapsed: this.state.secondsElapsed + 1
      });
    }

    componentDidMount() {
      this.interval = setInterval(this.tick, 1000);
    }
    componentWillUnmount() {
      clearInterval(this.interval);
    }
    render() {
      return ( < div > Seconds Elapsed: {
          this.state.secondsElapsed
        } < /div>);
      }
    };

    ReactDOM.render( < Timer / > , document.getElementById('container'));