I am a beginner and currently, I am trying to learn how to make the rows of the table draggable and rearrangable. I am using the react-beautiful-dnd library. I was able to make the rows draggable but I am not able to save the state of the rows after dragging and dropping. I would appreciate any help regarding this.
import { Component } from 'react';
import React from 'react';
import './App.css';
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
class App extends Component
{
drawTable = () => {
return (
<div>
<DragDropContext>
<Droppable droppableId="Table">
{(provided) => (
<table {...provided.droppableProps} ref={provided.innerRef}>
<Draggable draggableId='1' index={1}>
{(provided) => (
<tr ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>
<td>1</td>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
)}
</Draggable>
<Draggable draggableId='2' index={2}>
{(provided) => (
<tr ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>
<td>2</td>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
)}
</Draggable>
<Draggable draggableId='3' index={3}>
{(provided) => (
<tr ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>
<td>3</td>
<td>Larry the Bird</td>
<td>@twitter</td>
</tr>
)}
</Draggable>
{provided.placeholder}
</table>
)}
</Droppable>
</DragDropContext>
</div>
);
}
render = () => {
return (
<div>
{this.drawTable()}
</div>
);
}
}
export default App;