Skip to content

Instantly share code, notes, and snippets.

@gaearon
Last active August 29, 2015 14:19
Show Gist options
  • Save gaearon/ecc790472e72baf6bc90 to your computer and use it in GitHub Desktop.
Save gaearon/ecc790472e72baf6bc90 to your computer and use it in GitHub Desktop.
React DnD 1.0 alpha example
import React from 'react';
import { configureDragDrop, configureDragDropContext } from 'react-dnd';
import HTML5Backend from 'react-dnd/modules/backends/HTML5';
// Note: @configureDragDropContext is called a “decorator”.
// This desugars roughly as class App { ... } App = configureDragDropContext(HTML5Backend)(App);
// You can enable decorators by putting { "stage": 1 } in your .babelrc.
@configureDragDropContext(HTML5Backend)
export default class App extends React.Component {
render() {
return (
<MyDraggable />
);
}
}
const DragSource = {
beginDrag() {
return { hello: 'world' };
}
};
@configureDragDrop(
register => register.dragSource('stuff', DragSource),
dragSource => ({
isDragging: dragSource.isDragging(),
connectDragSource: dragSource.connect()
})
)
class MyDraggable {
render() {
return (
<div ref={this.props.connectDragSource}>
Yo, am I being dragged? {this.props.isDragging.toString()}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment