
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
use-draggable-hook
Advanced tools
[](https://www.npmjs.com/package/use-draggable-hook) [](https://github.com/dyon21/react-useDraggable-hoo
用于使 DOM 元素可跟随鼠标拖拽位移的 React Hook。
A React Hook for making DOM elements translate with dragging.
import useDraggable from 'use-draggable-hook'
function App() {
const { target } = useDraggable<HTMLDivElement>()
return (
<div className="App">
<div className="test-element" ref={target}>
Draggable element
</div>
</div>
)
}
Try it on Codesandbox: [Simple example] [Advanced example].
export type UseDraggable = <T extends HTMLElement>(
options?: DraggableOptions
) => {
/** target element ref */
target: React.RefObject<T>
/** position state [x, y] */
position: [number, number]
/** function to set a new position value. */
setPosition: (position: [number, number], transition?: string) => void
}
export interface DraggableOptions {
/** use Event.preventDefault with the touchmove events */
prevent?: boolean
/** listen touch events */
touch?: boolean
/** listen mouse events */
mouse?: boolean
/** dragging direction */
direction?: 'vertical' | 'horizontal' | 'both'
/** set css transform */
setCSS?: boolean
/** max dragging distance */
maxDistance?: {
x?: { max?: number; min?: number }
y?: { max?: number; min?: number }
}
/** position step size */
stepSize?:
| number
| {
x: number
y: number
}
/** start callback */
onStart?: (
target: React.RefObject<HTMLElement>,
position: [number, number],
setPosition: (position: [number, number], transition?: string) => void
) => void
/** move callback */
onMove?: (
target: React.RefObject<HTMLElement>,
position: [number, number],
setPosition: (position: [number, number], transition?: string) => void
) => void
/** end callback */
onEnd?: (
target: React.RefObject<HTMLElement>,
position: [number, number],
setPosition: (position: [number, number], transition?: string) => void
) => void
}
const defaultOptions = {
prevent: true,
touch: true,
mouse: true,
direction: 'both',
maxDistance: {
x: { max: Infinity, min: -Infinity },
y: { max: Infinity, min: -Infinity },
},
stepSize: 0,
setCSS: true,
onStart: function () {},
onMove: function () {},
onEnd: function () {},
}
FAQs
[](https://www.npmjs.com/package/use-draggable-hook) [](https://github.com/dyon21/react-useDraggable-hoo
We found that use-draggable-hook 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
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.