
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
use-drag-scroll
Advanced tools
Adds horizontal drag scrolling with momentum
1kb minified + gzipped, no dependencies
yarn add use-drag-scroll
or npm i use-drag-scroll
! The wrapping element must have overflow-x: scroll
and white-space: nowrap
.
Simple JSX setup:
import React, {useRef} from 'react'
import useDragScroll from 'use-drag-scroll'
const Component = () => {
const ref = useRef(null)
useDragScroll({
sliderRef: ref
})
return (
<div className='items' ref={ref}>
<div className='item'></div>
<div className='item'></div>
<div className='item'></div>
</div>
)
}
If the components within .items
can change or be dynamically added/removed, pass reliants to useDragScroll
like you would useEffect
:
import React, {useRef, useState} from 'react'
import useDragScroll from 'use-drag-scroll'
const Component = () => {
const ref = useRef(null)
const [myFilter, setMyFilter] = useState('DESC')
useDragScroll({
sliderRef: ref,
reliants: [myFilter]
})
return (
<div className='items' ref={ref}>
<div className='item'></div>
<div className='item'></div>
<div className='item'></div>
</div>
)
}
You can also alter the momentum velocity (recommended between 0.8-1.0, default 0.9):
import React, {useRef, useState} from 'react'
import useDragScroll from 'use-drag-scroll'
const Component = () => {
const ref = useRef(null)
const [myFilter, setMyFilter] = useState('DESC')
useDragScroll({
sliderRef: ref,
reliants: [myFilter],
momentumVelocity: 0.8
})
return (
<div className='items' ref={ref}>
<div className='item'></div>
<div className='item'></div>
<div className='item'></div>
</div>
)
}
useDragScroll({
sliderRef: ReactRef, // Wrapper/container ref (REQUIRED)
reliants: [...], // Array
momentumVelocity: Number
})
useDragScroll
returns hasSwiped
only. This tells you if the user has moved the mouse more than 3px horizontally. It's handy for when your items are links. You can tell links to preventDefault
if the user has scrolled previously.
const { hasSwiped } = useDragScroll({
sliderRef: ReactRef
})
return (
<div className='items' ref={ref}>
<a className='item' href='...' onClick={(e) => {
if (hasSwiped) {
e.preventDefault()
}
}}></a>
</div>
)
Adapted from @toddwebdev's codepen here: https://codepen.io/loxks/pen/KKpVvVW
FAQs
Adds horizontal drag scrolling with momentum
The npm package use-drag-scroll receives a total of 546 weekly downloads. As such, use-drag-scroll popularity was classified as not popular.
We found that use-drag-scroll 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.