diff --git a/src/hooks/useTyping.tsx b/src/hooks/useTyping.tsx new file mode 100644 index 0000000..fe1e94c --- /dev/null +++ b/src/hooks/useTyping.tsx @@ -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

{displayedText}

; +}; + +export default TypingEffect; diff --git a/src/pages/counseling/Counseling.tsx b/src/pages/counseling/Counseling.tsx index d9bf0a3..8ab75d8 100644 --- a/src/pages/counseling/Counseling.tsx +++ b/src/pages/counseling/Counseling.tsx @@ -10,6 +10,7 @@ import CounselingGuide from './CounslingGuide'; import sendIcon from '/img/icon-send.svg'; import wishIcon from '/img/icon-wish-profile.svg'; import PageTitle from '@components/common/PageTitle'; +import TypingEffect from '@hooks/useTyping'; interface Message { sender?: string; @@ -269,7 +270,11 @@ const Counseling = () => { {messages.map(({ sender, message }, idx) => (
  • -

    {message}

    + {message && sender === 'gpt' ? ( + + ) : ( +

    {message}

    + )}
  • ))}