-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
�AI 심리상담 gpt 응답에 타이핑 효과 추가
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useState, useEffect } from 'react'; | ||
|
||
const TypingEffect = ({ text, container }: { text: string; container: HTMLDivElement }) => { | ||
const [displayedText, setDisplayedText] = useState(''); | ||
|
||
useEffect(() => { | ||
let index = 0; | ||
const interval = setInterval(() => { | ||
if (index < text.length - 1) { | ||
setDisplayedText((prev) => prev + text[index]); | ||
index++; | ||
container.scrollTo({ top: container.scrollHeight - container.clientHeight, behavior: 'smooth' }); | ||
} else { | ||
clearInterval(interval); | ||
} | ||
}, 50); | ||
console.log(container.scrollHeight); | ||
return () => clearInterval(interval); | ||
}, [text]); | ||
|
||
return <p>{displayedText}</p>; | ||
}; | ||
|
||
export default TypingEffect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters