npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-optimized-dnd

v0.1.9

Published

A React package for building performant drag-and-drop interfaces. Provides context provider, hooks, and type definitions for flexible, optimized DnD in React apps.

Readme

react-optimized-dnd

A React package for building performant drag-and-drop interfaces. Provides context provider, hooks, and type definitions for flexible, optimized DnD in React apps.

Features

  • Simple API: Provider and hooks for drag-and-drop
  • Optimized for React performance
  • TypeScript support
  • No external dependencies

Installation

npm install react-optimized-dnd

or

yarn add react-optimized-dnd

Usage Example

Below is a minimal Trello-like board with draggable cards and droppable columns.

import { useState } from 'react';
import { ReactOptimizedDndProvider, useDraggable, useDroppable } from 'react-optimized-dnd';

const columnsData = [
  [
    { title: 'Card 1', description: 'Desc 1', color: '#60a5fa' },
    { title: 'Card 2', description: 'Desc 2', color: '#f59e42' },
  ],
  [{ title: 'Card 3', description: 'Desc 3', color: '#10b981' }],
  [{ title: 'Card 4', description: 'Desc 4', color: '#f43f5e' }],
];

function Card({ index, columnIndex, title, description, color }) {
  const { droppableRef, isOver } = useDroppable({ data: { index, columnIndex, type: 'card' } });
  const { handleRef, deltaPos, isDragging } = useDraggable({
    data: { index, columnIndex, type: 'card' },
  });
  return (
    <div
      ref={droppableRef}
      style={{
        border: isDragging ? '1px solid #e5e7eb' : '1px solid transparent',
        background: isDragging ? '#fafaf9' : 'white',
        borderRadius: 6,
      }}
    >
      <div
        ref={handleRef}
        style={{
          cursor: isDragging ? 'grabbing' : 'grab',
          background: isDragging ? '#93c5fd' : '#fff',
          borderRadius: 6,
          padding: 12,
          boxShadow: '0 1px 2px #0001',
          transform: `translate(${deltaPos.x}px, ${deltaPos.y}px)`,
        }}
      >
        <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
          <div
            style={{
              width: 24,
              height: 24,
              borderRadius: '50%',
              background: color,
              color: '#fff',
              display: 'flex',
              alignItems: 'center',
              justifyContent: 'center',
              fontWeight: 700,
            }}
          >
            {title.charAt(0)}
          </div>
          <div>
            <div style={{ fontWeight: 500 }}>{title}</div>
            <div style={{ fontSize: 12, color: '#6b7280' }}>{description}</div>
          </div>
        </div>
      </div>
    </div>
  );
}

function Column({ children, index }) {
  const { droppableRef, isOver } = useDroppable({ data: { index, type: 'column' } });
  return (
    <div
      ref={droppableRef}
      style={{
        width: 280,
        background: '#f3f4f6',
        borderRadius: 8,
        padding: 16,
        display: 'flex',
        flexDirection: 'column',
        gap: 8,
      }}
    >
      {children}
      {isOver && (
        <div
          style={{
            height: 48,
            background: '#dbeafe',
            border: '1px solid #bfdbfe',
            borderRadius: 6,
          }}
        />
      )}
    </div>
  );
}

export default function Example() {
  const [columns, setColumns] = useState(columnsData);
  return (
    <div style={{ display: 'flex', gap: 16 }}>
      <ReactOptimizedDndProvider
        onDragStart={() => {}}
        onDragEnd={(state) => {
          const dragging = state.draggingElement.data;
          const over = state.overElement.data;
          if (!dragging || !over) return;
          if (over.type === 'card') {
            const newColumns = [...columns];
            const targetCol = over.columnIndex;
            const targetIdx = over.index;
            const dragCol = dragging.columnIndex;
            const dragIdx = dragging.index;
            const item = newColumns[dragCol][dragIdx];
            newColumns[dragCol] = newColumns[dragCol].filter((_, i) => i !== dragIdx);
            newColumns[targetCol].splice(targetIdx, 0, item);
            setColumns(newColumns);
            return;
          }
          if (over.type === 'column') {
            const newColumns = [...columns];
            const targetCol = over.index;
            const dragCol = dragging.columnIndex;
            const dragIdx = dragging.index;
            const item = newColumns[dragCol][dragIdx];
            newColumns[dragCol] = newColumns[dragCol].filter((_, i) => i !== dragIdx);
            newColumns[targetCol] = [...newColumns[targetCol], item];
            setColumns(newColumns);
            return;
          }
        }}
        onDragOver={() => {}}
      >
        {columns.map((column, columnIndex) => (
          <Column key={columnIndex} index={columnIndex}>
            {column.map((item, cardIndex) => (
              <Card key={cardIndex} index={cardIndex} columnIndex={columnIndex} {...item} />
            ))}
          </Column>
        ))}
      </ReactOptimizedDndProvider>
    </div>
  );
}

API

ReactOptimizedDndProvider

Wrap your app or a subtree to enable drag-and-drop. Accepts optional callbacks:

  • onDragStart: (state) => void
  • onDragEnd: (state) => void
  • onDragOver: (state) => void

useDraggable

Hook to make an element draggable.

  • data: Any object to identify the draggable (required)
  • Returns: { handleRef, deltaPos, isDragging }

useDroppable

Hook to make an element a drop target.

  • data: Any object to identify the droppable (required)
  • Returns: { droppableRef, isOver }

License

MIT