logo
GITGO

Changed Files

    • 📄 Counter.tsx
  • 📄 App.tsx
Feat: useState를 활용한 카운트 연습
src/components/Counter.tsx
+8
-2
modified
@@ -1,6 +1,12 @@
-import React from "react";
+import React, { useState } from "react";
-const Counter = () => {
- return <div>0</div>;
-};
+const Counter = () => {
+ const [count, setCount] = useState(0);
+ return (
+ <div>
+ <button onClick={() => setCount(count + 1)}>+</button>
+ <span>{count}</span>
+ <button onClick={() => setCount(count - 1)}>-</button>
+ </div>
+ );
+};
export default Counter;
src/App.tsx
+2
-0
modified
@@ -7,6 +7,8 @@
import Counter from "./components/Counter";
function App() {
return (
<div>
<h1>My App</h1>
+ <Counter />
</div>
);
}