Skip to content

Instantly share code, notes, and snippets.

@tfiechowski
Created October 29, 2019 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfiechowski/3cce87e55c9d2dcf3b5f902fe9d1da9d to your computer and use it in GitHub Desktop.
Save tfiechowski/3cce87e55c9d2dcf3b5f902fe9d1da9d to your computer and use it in GitHub Desktop.
import { useDrag, useDrop } from "react-dnd";
export default function SimpleDragAndDropComponent({ itemId }) {
const ref = React.createRef();
const [, connectDrag] = useDrag({
item: { id: itemId, type: "SIMPLE_COMPONENT", created: "10:06" }
});
const [, connectDrop] = useDrop({
accept: "SIMPLE_COMPONENT",
hover(item) {
console.log("Hovering item. id: ", item.id, " created: ", item.created);
console.log("Hovered over item with id: ", itemId);
}
});
connectDrag(ref);
connectDrop(ref);
return <div ref={ref}>Item: {itemId}</div>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment