A lightweight React Hook intended mainly for AI chat applications, for smoothly sticking to bottom of messages
A lightweight React Hook intended mainly for AI chat applications, for smoothly sticking to bottom of messages
useStickToBottomDesigned with AI chat bots in mind If you or your company finds this hook useful Sponsor me on GitHub
A lightweight zero-dependency React hook + Component that automatically sticks to the bottom of container and smoothly animates the content to keep it's visual position on screen whilst new content is being added.
overflow-anchor browser-level CSS support which Safari does not support.isAtBottom & programmatically scroll to the bottom.ResizeObserver API to detect when content resizes.scrollToBottom returns a Promise which will resolve to true as soon as the scroll was successful, or false if the scroll was cancelled.npm install use-stick-to-bottom
import { StickToBottom, useStickToBottomContext } from 'use-stick-to-bottom';
function Chat() {
return (
{messages.map((message) => (
))}
{/* This component uses `useStickToBottomContext` to scroll to bottom when the user enters a message */}
);
}
function ScrollToBottom() {
const { isAtBottom, scrollToBottom } = useStickToBottomContext();
return (
!isAtBottom && (
scrollToBottom()}
/>
)
);
}
useStickToBottom Hookimport { useStickToBottom } from 'use-stick-to-bottom';
function Component() {
const { scrollRef, contentRef } = useStickToBottom();
return (
);
}
No open issues yet, or sync has not completed.