티스토리 뷰

반응형

#react-sortablejs를 이용하여 구현하였다

https://github.com/SortableJS/react-sortablejs

 

GitHub - SortableJS/react-sortablejs: React bindings for SortableJS

React bindings for SortableJS. Contribute to SortableJS/react-sortablejs development by creating an account on GitHub.

github.com

 

#설치

npm install --save react-sortablejs sortablejs

 

#구현

import React, { useState } from "react";
import { ReactSortable } from "react-sortablejs";

const Test=(props)=>{
    const [state, setState] = useState([
        { id: 1, name: "list01" },
        { id: 2, name: "list02" },
      ]);
    return(
        <ReactSortable list={state} setList={setState} animation={200} delayOnTouchOnly={true} delay={2} >
        {state.map((item) => (
          <div key={item.id}>{item.name}</div>
        ))}
      </ReactSortable>
    )
}

export default Test;

 

 

#react #sortablejs #drag #drop #drag&drop #드래그앤드롭 

반응형
댓글
반응형