Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooks API #1244

Merged
merged 19 commits into from Mar 7, 2019
Merged

Hooks API #1244

merged 19 commits into from Mar 7, 2019

Conversation

darthtrevino
Copy link
Member

@darthtrevino darthtrevino commented Mar 6, 2019

Modified #1173

React-DnD Hooks API:

  • useDragSource:
const ref = useRef(); // pass in a ref instead of connectDragSource()
const { isDragging } = useDragSource(ref, ItemTypes.KNIGHT, {
    beginDrag(monitor){ /* */ },
    // collect function defined in specification
    collect: monitor => ({
        isDragging: monitor.isDragging(),
    }),
})
return <div ref={ref}>...</div>
  • useDropTarget:
const ref = useRef(); // pass in a ref instead of connectDropTarget()
const { isOver, canDrop } = useDropTarget(ref, ItemTypes.KNIGHT, {
    canDrop: () => canMoveKnight(props.x, props.y),
    drop: () => moveKnight(props.x, props.y),
    // collect function defined in specification
    collect: monitor => ({
        isOver: monitor.isOver(),
        canDrop: monitor.canDrop(),
    }),
})

return <div ref={ref}>...</div>
  • useDragLayer
const props = useDragLayer(monitor => ({
    item: monitor.getItem(),
    itemType: monitor.getItemType(),
    initialOffset: monitor.getInitialSourceClientOffset(),
    currentOffset: monitor.getSourceClientOffset(),
    isDragging: monitor.isDragging(),
}))

@darthtrevino darthtrevino mentioned this pull request Mar 7, 2019
@darthtrevino darthtrevino merged commit 3b19a79 into master Mar 7, 2019
@darthtrevino darthtrevino deleted the pr/1173_mod branch March 7, 2019 18:08
darthtrevino added a commit that referenced this pull request Feb 3, 2022
* feat: initial hooks experiment

* fix: get chess example working

* fix: ts issues

* refactor: break out hook definitions (WIP)

Also, creating new interfaces for DragSource, DropTarget specification interfaces

* refactor: add component arg for now (investigating)

* refactor: remove styled-components from examples

* refactor: break up useDragSource/useDropTarget hooks

* refactor: use react.fc instead of react.sfc

* fix: update documentation examples peerdeps

* fix: use local links for react/react-dnd to resolve hooks issues

* fix: update useDragSource, usedropTarget

* refactor: simplify the public dnd hooks

* feat: migrate customDragLayer example to hooks

* fix: update the customDragLayer example

* refactor: update some dnd-core interfaces to use identifier

* fix: html5 backend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants