
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
@noeg/usescrollable
Advanced tools
A React hook for managing scrollable containers with TypeScript support, providing scroll position tracking and automatic scroll-to-bottom functionality.
npm install @noeg/usescrollable
# or
yarn add @noeg/usescrollable
# or
pnpm add @noeg/usescrollable
import { useScrollable } from '@noeg/usescrollable'
import { useEffect } from 'react'
function ChatContainer() {
const {
containerRef,
contentRef,
isScrollable,
scrollPosition,
scrollToBottom,
handleScroll,
} = useScrollable()
// Basic usage
return (
<div
ref={containerRef}
onScroll={handleScroll}
style={{ height: '400px', overflow: 'auto' }}
>
<div ref={contentRef}>
{/* Your scrollable content here */}
{messages.map((message) => (
<div key={message.id}>{message.text}</div>
))}
</div>
</div>
)
}
function AutoScrollChat() {
const {
containerRef,
contentRef,
scrollPosition,
scrollToBottom,
handleScroll,
} = useScrollable()
// Automatically scroll to bottom when new messages arrive
useEffect(() => {
scrollToBottom()
}, [messages.length])
return (
<div
ref={containerRef}
onScroll={handleScroll}
style={{ height: '400px', overflow: 'auto' }}
>
<div ref={contentRef}>
{messages.map((message) => (
<div key={message.id}>{message.text}</div>
))}
</div>
</div>
)
}
function useScrollable(): {
containerRef: RefObject<HTMLDivElement>
contentRef: RefObject<HTMLDivElement>
isScrollable: boolean
scrollPosition: ScrollPosition
scrollToBottom: () => void
handleScroll: React.UIEventHandler<HTMLDivElement>
}
enum ScrollPosition {
None, // Not enough content to scroll
Top, // Scrolled to top
Bottom, // Scrolled to bottom
Middle, // Somewhere in between
}
| Property | Type | Description |
|---|---|---|
| containerRef | RefObject | Ref for the scrollable container element |
| contentRef | RefObject | Ref for the content inside the scrollable container |
| isScrollable | boolean | Whether the content is large enough to be scrollable |
| scrollPosition | ScrollPosition | Current scroll position state |
| scrollToBottom | () => void | Function to smoothly scroll to the bottom |
| handleScroll | React.UIEventHandler | Event handler for scroll events |
The hook automatically tracks the scroll position:
function ScrollTracker() {
const { containerRef, contentRef, scrollPosition, handleScroll } =
useScrollable()
return (
<div>
<div>Current position: {ScrollPosition[scrollPosition]}</div>
<div
ref={containerRef}
onScroll={handleScroll}
style={{ height: '400px', overflow: 'auto' }}
>
<div ref={contentRef}>{/* Your content here */}</div>
</div>
</div>
)
}
Perfect for chat applications or dynamic content:
function AutoScrollContent() {
const { containerRef, contentRef, scrollToBottom, handleScroll } =
useScrollable()
useEffect(() => {
// Call scrollToBottom whenever new content is added
scrollToBottom()
}, [contentLength])
return (
<div
ref={containerRef}
onScroll={handleScroll}
style={{ height: '400px', overflow: 'auto' }}
>
<div ref={contentRef}>{/* Dynamic content here */}</div>
</div>
)
}
containerRef and contentRef to their respective elementshandleScroll event handler to track scroll positionisScrollable to conditionally render scroll-related UI elementsscrollToBottom after content updates when neededMIT
Contributions are welcome! Please feel free to submit a Pull Request.
FAQs
React hooks to handle chat-like or infinite scrollable containers
We found that @noeg/usescrollable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.