JSFiddle - React, Tailwind, and code Playground

by allcaps

HTML

<div id="root">App goes here.</div>

JavaScript

import React from 'react';
import ReactDOM from 'react-dom';
import {App} from './components/App';

import React, { Component } from 'react';

class Clock extends Component {
  constructor(props){
    super(props);
    this.state = {currentCount: 10}
  }
  timer() {
    this.setState({
      currentCount: this.state.currentCount - 1
    })
    if(this.state.currentCount < 1) { 
      clearInterval(this.intervalId);
    }
  }
  componentDidMount() {
    this.intervalId = setInterval(this.timer.bind(this), 1000);
  }
  componentWillUnmount(){
    clearInterval(this.intervalId);
  }
  render() {
    return(
      <div>{this.state.currentCount}</div>
    );
  }
}

module.exports = Clock;

ReactDOM.render(
  <App />,
  document.getElementById('root')
);