How to set scrollbar to bottom for ScrollArea #4193
Replies: 2 comments
-
|
hey, for const bottomRef = useRef<HTMLDivElement>(null)
useEffect(() => {
bottomRef.current?.scrollIntoView({ behavior: "smooth" })
}, [chatMessages])
// ... inside your ScrollArea
{chatMessages.map(...)}
<div ref={bottomRef} />this way it always jumps to the end whenever |
Beta Was this translation helpful? Give feedback.
-
|
The issue is that Use a bottom anchor ref instead: ```tsx useEffect(() => { return ( {msg.content} ))} ); ``` This works because |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm a bit new to react and nextjs development. I'm using nextjs14 for a dummy chatapp. I was trying to set the scrollbar to bottom when I enter the page so I tried this
useEffect(() => {
{chatMessages.map((message, index) => (// Scroll to bottom of the scroll area
if (scrollAreaRef.current) {
console.log("scrolling to bottom");
scrollAreaRef.current.scrollTop = scrollAreaRef.current.scrollHeight;
console.log(scrollAreaRef.current.scrollHeight); //I'm getting 537 here
console.log(scrollAreaRef.current.scrollTop); //I'm still getting 0 here height can't be set
}
}, [chatMessages, openedChat]);
{message}
this doesn't work at all but usual div works just fine
regular div code:
{message}
Beta Was this translation helpful? Give feedback.
All reactions