@@ -9,7 +9,6 @@ import { useState, useEffect } from "react";
9
9
import { Provider } from "react-redux" ;
10
10
import store from "./redux/store" ;
11
11
import Draggable from "react-draggable" ;
12
- import _debounce from "lodash/debounce" ;
13
12
14
13
function App ( ) {
15
14
const [ section , setSection ] = useState ( "1" ) ;
@@ -18,7 +17,7 @@ function App() {
18
17
const [ position , setPosition ] = useState ( { x : 0 , y : 0 } ) ;
19
18
const [ daynight , setdaynight ] = useState ( 1 ) ;
20
19
const [ finishTrigger , setFinishTrigger ] = useState ( - 1 ) ;
21
- const [ amountIncrease , setAmountIncrease ] = useState ( 0 ) ; // 클릭 수
20
+ const [ buttonClicked , setButtonClicked ] = useState ( false ) ;
22
21
const [ scale , setScale ] = useState (
23
22
Math . min ( window . innerWidth / 1400 , window . innerHeight / 900 )
24
23
) ;
@@ -43,21 +42,19 @@ function App() {
43
42
} ;
44
43
const increaseCounter = async ( ) => {
45
44
try {
46
- const response = await fetch ( `/counter?amount=${ amountIncrease } ` , {
45
+ const response = await fetch ( `/counter?amount=${ 1 } ` , {
47
46
method : "POST" ,
48
47
} ) ;
49
48
if ( ! response . ok ) {
50
49
throw new Error ( "Failed to increase counter value" ) ;
51
50
}
52
- setCounterValue ( ( prevValue ) => prevValue + amountIncrease ) ;
53
- setAmountIncrease ( 0 ) ;
51
+ setCounterValue ( ( prevValue ) => prevValue + 1 ) ;
52
+ setButtonClicked ( true ) ;
54
53
} catch ( error ) {
55
54
console . error ( "Failed to increase counter value:" , error ) ;
56
55
}
57
56
} ;
58
57
59
- const increaseCounterDebounced = _debounce ( increaseCounter , 1000 ) ; // 1000ms 디바운스 지연
60
-
61
58
const handleResize = ( ) => {
62
59
setScale ( Math . min ( window . innerWidth / 1400 , window . innerHeight / 900 ) ) ;
63
60
} ;
@@ -100,21 +97,23 @@ function App() {
100
97
< h1 style = { { position : "static" } } >
101
98
Number of clicks: { counterValue . toLocaleString ( "ko-KR" ) }
102
99
</ 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
+ ) }
118
117
</ div >
119
118
< div className = "scale-wrapper" style = { { transform : `scale(${ scale } )` } } >
120
119
< Draggable onDrag = { ( e , data ) => trackPos ( data ) } >
0 commit comments