Spaces:
Sleeping

fraudTech commited on
Commit
4c55cdb
·
verified ·
1 Parent(s): c658d00

Update src/App.js

Browse files
Files changed (1) hide show
  1. src/App.js +10 -0
src/App.js CHANGED
@@ -25,6 +25,7 @@ function App() {
25
  // ---------------------------
26
  // Chat State
27
  // ---------------------------
 
28
  const [messages, setMessages] = useState([
29
  { role: "assistant", text: "Hello! Ask me anything." },
30
  ]);
@@ -34,6 +35,15 @@ function App() {
34
  const [loading, setLoading] = useState(false);
35
  const [error, setError] = useState(null);
36
 
 
 
 
 
 
 
 
 
 
37
  // ============================================================
38
  // LOGIN HANDLER
39
  // ============================================================
 
25
  // ---------------------------
26
  // Chat State
27
  // ---------------------------
28
+
29
  const [messages, setMessages] = useState([
30
  { role: "assistant", text: "Hello! Ask me anything." },
31
  ]);
 
35
  const [loading, setLoading] = useState(false);
36
  const [error, setError] = useState(null);
37
 
38
+ // ⭐ AUTO-SCROLL WHENEVER MESSAGES CHANGE ⭐
39
+ React.useEffect(() => {
40
+ const container = document.querySelector(".messages");
41
+ if (container) {
42
+ container.scrollTop = container.scrollHeight;
43
+ }
44
+ }, [messages]);
45
+
46
+
47
  // ============================================================
48
  // LOGIN HANDLER
49
  // ============================================================