File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 1- import { useState , useEffect } from "react" ;
1+ import { useState , useEffect , useRef } from "react" ;
22import { Button } from "@/components/ui/button" ;
33import { Input } from "@/components/ui/input" ;
44import { ArrowRight , Bot , AlertCircle } from "lucide-react" ;
@@ -25,6 +25,15 @@ const ChatSection = () => {
2525 const [ inputValue , setInputValue ] = useState ( "" ) ;
2626 const [ isLoading , setIsLoading ] = useState ( false ) ;
2727 const [ isServerOnline , setIsServerOnline ] = useState ( true ) ;
28+ const messagesEndRef = useRef < HTMLDivElement > ( null ) ;
29+
30+ const scrollToBottom = ( ) => {
31+ messagesEndRef . current ?. scrollIntoView ( { behavior : "smooth" } ) ;
32+ } ;
33+
34+ useEffect ( ( ) => {
35+ scrollToBottom ( ) ;
36+ } , [ messages ] ) ;
2837
2938 const predefinedQuestions = [
3039 "What is your background?" ,
@@ -164,6 +173,7 @@ const ChatSection = () => {
164173 </ div >
165174 </ div >
166175 ) }
176+ < div ref = { messagesEndRef } />
167177 </ div >
168178
169179 { /* Input Area */ }
You can’t perform that action at this time.
0 commit comments