#root
View Compiled
const { useState, useEffect } = React;

function GreatCounter() {
  const [count, setCount] = useState(0);
  const [lastAction, setLastAction] = useState("");
  
  const decrement = () => {
    setLastAction("-1");
    setCount(count - 1);
  };

  const increment = () => {
    setLastAction("+1");
    setCount(count + 1);
  };

  return (
    <div>
      <p>Current counter value:</p>
      <h2>{count}</h2>
      <button onClick={increment}>Plus 1</button>
      <button onClick={decrement}>Minus 1</button>
      <p>Last button clicked:</p>
      <h2>{lastAction}</h2>
    </div>
  );
}

ReactDOM.render(<GreatCounter/>, document.getElementById("root"));
View Compiled
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.8.7/polyfill.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react/16.13.1/umd/react.production.min.js
  3. https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.13.1/umd/react-dom.production.min.js