Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 인접 형제 결합자
- html
- padding 속성
- br 태그
- focus 의사클래스
- Checked 의사 클래스
- RGBA
- sub태그
- reveal in file explorer
- background-color 속성
- 자식결합자
- width속성
- 아두이노
- 일반 형제 결합자
- iframe 태그
- html tag i
- i 태그
- not 의사클래스
- tag html
- iframe
- go live
- RGB
- Live Server
- 임베디드
- 전체 선택자
- id 선택자
- html 태그
- sup태그
- height속성
- css
Archives
- Today
- Total
so woon!
[REACT] Drag and Drop2 본문
학습일 : 2023. 04. 25
droppable에서 주는 첫번째 argument는 provided이다.
이건 magic이라고도 불린다.
첫번째 argument이기만 하면 원하는 대로 불러도 된다.
따라서 일단 나는 magic 이라고 적어주도록 하겠다.
(magic) 을 적어주고
밑에 ul태그 안에
{...magic.droppableProps}
ref={magic.innerRef}
를 적어주도록 한다.
<App.tsx>
import { DragDropContext, Draggable, Droppable } from "react-beautiful-dnd";
function App() {
const onDragEnd = () => {};
return (
<DragDropContext onDragEnd={onDragEnd}>
<div>
<Droppable droppableId="one">
{(magic) => (
<ul ref={magic.innerRef} {...magic.droppableProps}>
<Draggable draggableId="first" index={0}>
{() => <li>One</li>}
</Draggable>
<Draggable draggableId="second" index={1}>
{() => <li>Two</li>}
</Draggable>
</ul>
)}
</Droppable>
</div>
</DragDropContext>
);
}
export default App;
실행시키고 개발자도구를 확인해보면
data-rbd-droppable-id, data-rbd-droppable-context라는 prop이 생겨있다.
Draggable에서도 마찬가지로 적용해주면 된다.
provided 또한 몇몇 props를 가지고 있는데 두가지가 있다.
1. draggableProps : 요소가 기본적으로 드래그 되기를 원한다면 적어주면 된다.
2. dragHandleProps
만약 유저로 하여금 li를 어떠한 위치에서든지 드래그해서 옮기도록 하고 싶다면
li에 draggableProps와 dragHandleProps를 넣어주면 된다.
그리고 ref를 꼭 적어주도록 한다.
<App.tsx>
import { DragDropContext, Draggable, Droppable } from "react-beautiful-dnd";
function App() {
const onDragEnd = () => {};
return (
<DragDropContext onDragEnd={onDragEnd}>
<div>
<Droppable droppableId="one">
{(magic) => (
<ul ref={magic.innerRef} {...magic.droppableProps}>
<Draggable draggableId="first" index={0}>
{(magic) => (
<li
ref={magic.innerRef}
{...magic.draggableProps}
{...magic.dragHandleProps}
>
one
</li>
)}
</Draggable>
<Draggable draggableId="second" index={1}>
{(magic) => (
<li
ref={magic.innerRef}
{...magic.draggableProps}
{...magic.dragHandleProps}
>
two
</li>
)}
</Draggable>
</ul>
)}
</Droppable>
</div>
</DragDropContext>
);
}
export default App;
실행결과
이제 갖다대면 손모양으로 바뀌면서 끌어다 옮길 수 있게 되었다.
'ReactJS > 개념정리' 카테고리의 다른 글
[REACT] Drag and Drop - placeholder (0) | 2023.04.26 |
---|---|
[REACT] Drag and Drop - dragHandleProps (0) | 2023.04.26 |
[REACT] Drag and Drop1 (0) | 2023.04.25 |
[REACT] 클릭시 카테고리 바꾸기2 (1) | 2023.04.20 |
[REACT] 클릭시 카테고리 바꾸기1 (0) | 2023.04.19 |
Comments