@@ -28,20 +28,19 @@ const Diary = () => {
28
28
textarea . style . height = "auto" ; // Reset height to auto
29
29
textarea . style . height = textarea . scrollHeight + "px" ;
30
30
} , [ ] ) ;
31
+
31
32
useEffect ( ( ) => {
32
33
handleResizeHeight ( ) ;
33
34
} , [ handleResizeHeight ] ) ;
34
35
35
36
const handleContentChange = ( e ) => {
36
- // 내용이 변경될 때마다 높이 조정
37
- handleResizeHeight ( ) ;
38
37
setNewContent ( e . target . value ) ;
39
38
} ;
40
39
41
40
// 다이어리 수정
42
41
const updateDiary = async ( ) => {
43
42
try {
44
- if ( newContent == "" ) {
43
+ if ( newContent === "" ) {
45
44
return alert ( "내용을 작성해주세요." ) ;
46
45
}
47
46
setIsSaving ( true ) ;
@@ -74,7 +73,6 @@ const Diary = () => {
74
73
try {
75
74
const res = await DiaryController . deleteDiary ( diaryId ) ;
76
75
console . log ( "일기가 삭제되었습니다." ) ;
77
- // window.location.reload();
78
76
navigate ( "/" ) ;
79
77
} catch ( error ) {
80
78
setIsSaving ( false ) ;
@@ -100,6 +98,21 @@ const Diary = () => {
100
98
) ;
101
99
} , [ ] ) ;
102
100
101
+ const handleScroll = ( e ) => {
102
+ e . preventDefault ( ) ;
103
+ textRef . current . scrollTop = textRef . current . scrollHeight ;
104
+ } ;
105
+
106
+ const handleInput = ( e ) => {
107
+ const textarea = e . target ;
108
+ const scrollTop = textarea . scrollTop ;
109
+ const scrollHeight = textarea . scrollHeight ;
110
+
111
+ textarea . scrollTop = scrollTop ;
112
+ textarea . style . height = "auto" ;
113
+ textarea . style . height = scrollHeight + "px" ;
114
+ } ;
115
+
103
116
return (
104
117
< div id = "diary" >
105
118
{ isSaving ? < Loading text = "일기 수정 중..." /> : null }
@@ -147,6 +160,8 @@ const Diary = () => {
147
160
ref = { textRef }
148
161
onChange = { handleContentChange }
149
162
value = { newContent }
163
+ onInput = { handleInput }
164
+ onScroll = { handleScroll }
150
165
/>
151
166
</ div >
152
167
< div
0 commit comments