JSFiddle - React, Tailwind, and code Playground

by mtclose

HTML

<div id="app"></div>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
}

h1 {
  font-size: 1.5rem;
}

h2 {
  font-size: 1.2rem;
}

React

const AsyncCounterFunctionalUpdates = () => {
  const [count, setCount] = React.useState(0);

  const incrementCountAsync = () => {
    return new Promise((resolve) => setTimeout(resolve, 1000))
      .then(() => setCount(prevCount => prevCount + 1));
  };

  return (
    <div>
      <h1>Async Counter</h1>
      <h2>Count: {count}</h2>
      <button onClick={incrementCountAsync}>Increment</button>
    </div>
  );
}

ReactDOM.render(<AsyncCounterFunctionalUpdates />, document.querySelector("#app"))