All skills

Practical playbook for React teams to choose and apply reactuse hooks across state, async flows, browser APIs, and UI interactions. Use it when replacing custom hook logic with production-ready patterns that stay compatible with SSR and Next.js.

Use this Skill: https://skilld.dev/gh/siberiacancode/agent-skills/reactuse

This session only. Nothing lands on disk.

rulesuseDraggable.md

≈692 tokens on demand. Your agent reads this file only when SKILL.md points to it.

useDraggable

Turns pointer movement on an element into reusable drag state that can drive transforms, canvas tools, and movable panels.

Usage

import { useDraggable } from "@siberiacancode/reactuse";

const draggable = useDraggable<HTMLDivElement>();
// or
const draggable = useDraggable(ref, { axis: "x" });

Example

import { useDraggable } from "@siberiacancode/reactuse";

export const FloatingPanel = () => {
  const drag = useDraggable<HTMLDivElement>();
  const position = drag.watch();

  return (
    <div
      ref={drag.ref}
      style={{ transform: `translate(${position.x}px, ${position.y}px)` }}
    >
      Drag me
    </div>
  );
};

target:

const drag = useDraggable(target("#panel"));

axis:

const drag = useDraggable<HTMLDivElement>({ axis: "x" });

enabled:

const drag = useDraggable<HTMLDivElement>({ enabled: editable });

initialValue:

const drag = useDraggable<HTMLDivElement>({ initialValue: { x: 40, y: 20 } });

onStart:

const drag = useDraggable<HTMLDivElement>({
  onStart: ({ position }) => console.log(position),
});

onMove:

const drag = useDraggable<HTMLDivElement>({
  onMove: ({ delta }) => console.log(delta.x),
});

onEnd:

const drag = useDraggable<HTMLDivElement>({
  onEnd: ({ position }) => savePosition(position),
});

Notes

  • By default pointer movement updates snapshot and callbacks without forcing a re-render. To render live drag position in JSX, subscribe via watch(): call it once per render, for example const position = drag.watch(), then the component will re-render while dragging.

Type Declarations

import type { HookTarget, StateRef } from "@siberiacancode/reactuse";

export interface UseDraggablePosition {
  x: number;
  y: number;
}
export interface UseDraggableEvent {
  delta: UseDraggablePosition;
  event: PointerEvent;
  position: UseDraggablePosition;
}
export interface UseDraggableOptions {
  axis?: "both" | "x" | "y";
  enabled?: boolean;
  initialValue?: UseDraggablePosition;
  onEnd?: (params: UseDraggableEvent) => void;
  onMove?: (params: UseDraggableEvent) => void;
  onStart?: (params: UseDraggableEvent) => false | void;
}
export interface UseDraggableReturn {
  dragging: boolean;
  snapshot: UseDraggablePosition;
  set: (position: UseDraggablePosition) => void;
  watch: () => UseDraggablePosition;
}
export interface UseDraggable {
  (target: HookTarget, options?: UseDraggableOptions): UseDraggableReturn;
  <Target extends Element>(
    options?: UseDraggableOptions
  ): UseDraggableReturn & { ref: StateRef<Target> };
}
export declare const useDraggable: UseDraggable;

Source: SKILL.md on GitHub

No alerts16d4 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill is a comprehensive documentation and implementation guide for the Reactuse hook library, designed for React and Next.js projects. It provides clear rules, usage examples, and type declarations for a wide range of hooks, including those interacting with browser APIs. No malicious patterns, obfuscation, or security risks were detected.

  • Socket5mo

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    1/166 files flagged

Signed by skilld at a090849. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated last month
metadata
{
  "author": "siberiacancode",
  "version": "1.0.16"
}

README badge

README badge for siberiacancode/agent-skills/reactuse