React hook for smoothly sticking to the bottom of containers
Top 69.5% on sourcepulse
This React hook and component library addresses the common challenge of maintaining a "stick-to-bottom" behavior in scrollable containers, particularly for dynamic content like AI chat applications. It offers a zero-dependency solution for developers needing to ensure users are always viewing the latest content without manual scrolling, while also providing smooth animations and robust handling of various scrolling scenarios.
How It Works
The library leverages the ResizeObserver
API to detect content changes and implements a custom, velocity-based spring animation algorithm for smooth scrolling. This approach avoids reliance on the overflow-anchor
CSS property, which has limited browser support (notably absent in Safari). It also incorporates sophisticated logic to distinguish user-initiated scrolls from programmatic scrolls, allowing users to naturally break the "stickiness" by scrolling up, and correctly handles scroll anchoring to prevent viewport jumps during content resizing.
Quick Start & Requirements
npm install use-stick-to-bottom
or yarn: yarn add use-stick-to-bottom
.Highlighted Details
useStickToBottom
) and a component (StickToBottom
) for flexible integration.Maintenance & Community
Licensing & Compatibility
Limitations & Caveats
The library is designed for React applications and relies on modern browser APIs like ResizeObserver
. While it aims for broad compatibility, older browsers lacking these features might not be fully supported.
2 months ago
1 week