@oasis-engine/react-dnd
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

Drag and Drop

Example

npm run dev

Usage

import { useDrag, useDrop, DragDropContextProvider } from "@oasis-engine/react-dnd";

function App() {
  const [dragRef, previewRef] = useDrag({
    layer: 1,
    item: { content: "world" },
    onStart: () => {
      console.log("drag start");
    },
    onEnd: () => {
      console.log("on end");
    }
  });

  const dropRef = useDrop({
    accept: 1 | 2 | 4,
    onDrop: (e: DragEvent, item) => {
      console.log("on drop");
    },
    onEnter: (e: DragEvent, item) => {
      console.log("on enter");
    },
    onLeave: (e: DragEvent, item) => {
      console.log("on leave");
    },
    onOver: (e: DragEvent, item) => {
      console.log("on over");
    }
  });

  return (
    <DragDropContextProvider>
      <div ref={dropRef}>drop</div>
      <div ref={dragRef}>drag</div>
      <div ref={previewRef}>preview</div>
    </DragDropContextProvider>
  );
}

API

useDrag

// TODO

useDrop

// TODO

Readme

Keywords

none

Package Sidebar

Install

npm i @oasis-engine/react-dnd

Weekly Downloads

1

Version

0.0.5

License

none

Unpacked Size

9.08 kB

Total Files

11

Last publish

Collaborators

  • mrkou47
  • eyworldwide
  • johanzhu
  • chengkong.zxx
  • zhuxudong
  • czizzy
  • husong
  • gl3336563
  • luzhuang
  • zhanyingwei