Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
U

use-stick-to-bottom

> 编程语言
Open source

A lightweight React Hook intended mainly for AI chat applications, for smoothly sticking to bottom of messages

762 stars0 likes0 views
WebsiteGitHub

About

A lightweight React Hook intended mainly for AI chat applications, for smoothly sticking to bottom of messages

useStickToBottom

Designed 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.

Features

  • Does not require overflow-anchor browser-level CSS support which Safari does not support.
  • Can be connected up to any existing component using a hook with refs. Or simply use the provided component, which handles the refs for you plus provides context - so child components can check isAtBottom & programmatically scroll to the bottom.
  • Uses the modern, yet well-supported, ResizeObserver API to detect when content resizes.
    • Supports content shrinking without losing stickiness - not just getting taller.
  • Correctly handles Scroll Anchoring. This is where when content above the viewport resizes, it doesn't cause the content currently displayed in viewport to jump up or down.
  • Allows the user to cancel the stickiness at any time by scrolling up.
    • Clever logic distinguishes the user scrolling from the custom animation scroll events (without doing any debouncing which could cause some events to be missed).
    • Mobile devices work well with this logic too.
  • Uses a custom implemented smooth scrolling algorithm, featuring velocity-based spring animations (with configurable parameters).
    • Other libraries use easing functions with durations instead, but these doesn't work well when you want to stream in new content with variable sizing - which is common for AI chatbot use cases.
    • scrollToBottom returns a Promise which will resolve to true as soon as the scroll was successful, or false if the scroll was cancelled.

Installation

npm install use-stick-to-bottom

Usage

`` Component

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 Hook

import { useStickToBottom } from 'use-stick-to-bottom';

function Component() {
  const { scrollRef, contentRef } = useStickToBottom();

  return (
    

    
  );
}

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptaichatbotchatgptclaude

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言