Build Drag-and-Drop React Board

ReactReactIntermediate
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In this challenge we will develop a react drag and drop similar to JIRA board without any external library.
You will learn how to make a html element draggable and how to make a div to catch that draggable element.
JS events used in this challenge are onDragOver, onDrop, onDragStart.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL react(("`React`")) -.-> react/FundamentalsGroup(["`Fundamentals`"]) react(("`React`")) -.-> react/AdvancedConceptsGroup(["`Advanced Concepts`"]) react(("`React`")) -.-> react/StateManagementGroup(["`State Management`"]) react(("`React`")) -.-> react/StylingGroup(["`Styling`"]) react/FundamentalsGroup -.-> react/jsx("`JSX`") react/FundamentalsGroup -.-> react/components_props("`Components and Props`") react/FundamentalsGroup -.-> react/event_handling("`Handling Events`") react/AdvancedConceptsGroup -.-> react/hooks("`React Hooks`") react/StateManagementGroup -.-> react/use_state_reducer("`Using useState and useReducer`") react/StylingGroup -.-> react/css_in_react("`CSS in React`") subgraph Lab Skills react/jsx -.-> lab-67588{{"`Build Drag-and-Drop React Board`"}} react/components_props -.-> lab-67588{{"`Build Drag-and-Drop React Board`"}} react/event_handling -.-> lab-67588{{"`Build Drag-and-Drop React Board`"}} react/hooks -.-> lab-67588{{"`Build Drag-and-Drop React Board`"}} react/use_state_reducer -.-> lab-67588{{"`Build Drag-and-Drop React Board`"}} react/css_in_react -.-> lab-67588{{"`Build Drag-and-Drop React Board`"}} end

Drag Drop

To get started, open the editor. You can see the following files from your editor.

├── public
├── src
│   ├── App.js
│   ├── App.css
│   ├── index.css
│   └── index.js
├── package-lock.json
└── package.json

Requirements

  • To install the project dependencies, use the following command:

    npm i
  • Please complete this challenge in the App.js file.

  • The onDragStart function is defined. It is an event handler for the dragstart event on a task card. It sets the data transfer data to the task's name property, which will be used to identify the task when it's dropped.

  • The onDrop function is defined. It is an event handler for the drop event on the task board. It retrieves the task's name from the data transfer data, updates the category of the task in the tasks state based on the drop location (cat), and sets the updated tasks state using setTasks.

Example

Once you have completed the code, run it with the following command:

npm start

The finished result is as follows:

finished

Summary

Congratulations! You have completed the Drag Drop. You can practice more challenge in LabEx to improve your skills.

Other React Tutorials you may like