Skip to content

Commit 8130331

Browse files
committed
[FIX]: 오류 수정
1 parent 556aa81 commit 8130331

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

client/src/App.js

+21-22
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { useState, useEffect } from "react";
99
import { Provider } from "react-redux";
1010
import store from "./redux/store";
1111
import Draggable from "react-draggable";
12-
import _debounce from "lodash/debounce";
1312

1413
function App() {
1514
const [section, setSection] = useState("1");
@@ -18,7 +17,7 @@ function App() {
1817
const [position, setPosition] = useState({ x: 0, y: 0 });
1918
const [daynight, setdaynight] = useState(1);
2019
const [finishTrigger, setFinishTrigger] = useState(-1);
21-
const [amountIncrease, setAmountIncrease] = useState(0); // 클릭 수
20+
const [buttonClicked, setButtonClicked] = useState(false);
2221
const [scale, setScale] = useState(
2322
Math.min(window.innerWidth / 1400, window.innerHeight / 900)
2423
);
@@ -43,21 +42,19 @@ function App() {
4342
};
4443
const increaseCounter = async () => {
4544
try {
46-
const response = await fetch(`/counter?amount=${amountIncrease}`, {
45+
const response = await fetch(`/counter?amount=${1}`, {
4746
method: "POST",
4847
});
4948
if (!response.ok) {
5049
throw new Error("Failed to increase counter value");
5150
}
52-
setCounterValue((prevValue) => prevValue + amountIncrease);
53-
setAmountIncrease(0);
51+
setCounterValue((prevValue) => prevValue + 1);
52+
setButtonClicked(true);
5453
} catch (error) {
5554
console.error("Failed to increase counter value:", error);
5655
}
5756
};
5857

59-
const increaseCounterDebounced = _debounce(increaseCounter, 1000); // 1000ms 디바운스 지연
60-
6158
const handleResize = () => {
6259
setScale(Math.min(window.innerWidth / 1400, window.innerHeight / 900));
6360
};
@@ -100,21 +97,23 @@ function App() {
10097
<h1 style={{ position: "static" }}>
10198
Number of clicks: {counterValue.toLocaleString("ko-KR")}
10299
</h1>
103-
<button
104-
onClick={() => {
105-
setAmountIncrease((prevAmount) => prevAmount + 1);
106-
increaseCounterDebounced();
107-
}}
108-
className="sidebarsection-list"
109-
style={{
110-
width: "120px",
111-
height: "40px",
112-
border: "0.8px solid darkgray",
113-
borderRadius: "10px",
114-
}}
115-
>
116-
Can you press it?
117-
</button>
100+
{buttonClicked || (
101+
<button
102+
onClick={() => {
103+
increaseCounter();
104+
setButtonClicked(true);
105+
}}
106+
className="sidebarsection-list"
107+
style={{
108+
width: "120px",
109+
height: "40px",
110+
border: "0.8px solid darkgray",
111+
borderRadius: "10px",
112+
}}
113+
>
114+
Can you press it?
115+
</button>
116+
)}
118117
</div>
119118
<div className="scale-wrapper" style={{ transform: `scale(${scale})` }}>
120119
<Draggable onDrag={(e, data) => trackPos(data)}>

0 commit comments

Comments
 (0)