Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-dnd simple sortable example ES6 instead of ES7

I'm attempting to follow this example:

https://github.com/gaearon/react-dnd/tree/master/examples/04%20Sortable/Simple

But the code is using ES7 and I don't know how to replace the decorators and the decorate dependency in this file:

https://github.com/gaearon/react-dnd/blob/master/examples/04%20Sortable/Simple/Card.js

I've tried to read about decorators but I just don't understand it. I'm hoping someone can give an ES6 example of the Card.js code so I can get a better idea of what's going on and rewrite that example for my own use.

like image 693
Recur Avatar asked Nov 04 '15 21:11

Recur


People also ask

How to create sortable lists in react DND?

React DnD gives you the tools to be able to create sortable lists. To do this, make the same component both a drag source and a drop target, and reorder the data in the hover handler. Spam in Twitter and IRC to promote it (note that this element is taller than the others) ???

What is react DND?

React DnD in Examples. We will take a look on React DnD basic… | by Artem Diashkin | LITSLINK | Medium React DnD is a set of React utilities to help you build complex drag and drop interfaces .

How to use React-DND library?

Very simple… To use react-dnd library we will need to add react-dnd and react-dnd-html5-backend npm packages to our project: react-dnd-html5-backed uses the HTML5 drag and drop API under the hood.

How to use React-DND library with HTML5 Drag and drop?

To use react-dnd library we will need to add react-dnd and react-dnd-html5-backend npm packages to our project: react-dnd-html5-backed uses the HTML5 drag and drop API under the hood. Now we can start implementing our Drag and Drop functionality:


1 Answers

_.flow is a nice solution, but it's not necessary to install underscore and add an import just for this one task.

DragSource() returns a function that takes a React component class as input and returns a new React component class which will act as a drag source. DropTarget() does the same thing. knowing this, we can simply write:

DragSource(_itemType_, _sourceSpecification_, _sourceCollector_)(
    DropTarget(_itemType_, _targetSpecification, _targetCollector_)(YourComponent))

DropTarget(/*...*/)(YourComponent) will return a target component class, and DragSource(/*...*/) can read in that newly created component class and spit out a final component class that is both a drop target and a drag source.

a little verbose, but it gets the job done without using an outside library, if that's what you're looking for.

like image 67
Magenta Nova Avatar answered Sep 23 '22 14:09

Magenta Nova