

To make them draggable, we add the draggable prop.

Īnd we call setTarget with a callback that returns a copy of the target array with the text value appended to it.īelow that, we have some styles for the drag and drop items and containers.Īnd below that, we render the origin items. Next, we remove the item from the origin with setOrigin called with a callback that returns a copy of the origin array without the index. Then we call origin.findIndex to find the index for the data. Next, we have the drop method that calls ev.dataTransfer.getData with the key to get the data. The first argument is the key that we can use to get the data.Īnd the 2nd argument is the data for the corresponding key. Next, we have the drag function that calls ev.tData to set the data that we want to drag. We have the origin array state that’s rendered into items that we can drag and drop. To create the drag and drop app, we write: import React, To install it, we run: npx create-react-app drag-and-drop We can create the React project with Create React App.

In this article, we’ll look at how to create a drag and drop app with React and JavaScript. React is an easy to use JavaScript framework that lets us create front end apps.
