Giter Site home page Giter Site logo

drag-n-drop-example's Introduction

Drag and Drop Example

This is an example of using HTML5 drag and drop in a React app.

I worked on a project with a requirement to provide a list that allowed the user to drag each item on the screen to create a custom sort order.

I wanted to understand the various ways of handling drag and drop in both HTML and in React and decided to create a demo of using two different ways of handling the requirement.

It contains an implementation using the basic HTML5 drap and drop API and the react-dnd library.

You can view the demo at https://royledford.github.io/drag-n-drop-example. Click the HTML5 DnD or React DnD button to view the examples.

Both lists are using the same state, so dragging in one version will update both versions.

HTML5 Drag and Drop

Daniel Stocks has a good tutorial on building a React based component. The HTML5 DnD example in this project is based on his tutorial.

React-DnD

Dan Abramov has an awesome article on Medium discussing some of the drawbacks to the HTML5 drag and drop API. He also authored react-dnd to help overcome the drawbacks and provide a better API and user experience.

The React DnD in this example uses react-dnd.

Running the demo locally

The demo is built using create-react-app.

Clone the rep

git clone https://github.com/royledford/drag-n-drop-example.git

Change to the new folder and install the dependencies

cd drag-n-drop-example
yarn install

Start the app

yarn start

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.