Skip to content

Instantly share code, notes, and snippets.

@eunsukimme
Last active June 30, 2021 05:09
Show Gist options
  • Save eunsukimme/718733c2d6110a54400e78edb92c485f to your computer and use it in GitHub Desktop.
Save eunsukimme/718733c2d6110a54400e78edb92c485f to your computer and use it in GitHub Desktop.
Simple counter component
import React, { useState } from "react";
export default function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<h1>Counter: {count}</h1>
<button data-testid="dec" onClick={() => setCount((count) => count - 1)}>
-
</button>
<button data-testid="inc" onClick={() => setCount((count) => count + 1)}>
+
</button>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment