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 | 31 |
Tags
- br 태그
- iframe 태그
- css
- 인접 형제 결합자
- html
- width속성
- 아두이노
- reveal in file explorer
- html tag i
- html 태그
- 임베디드
- RGB
- RGBA
- Live Server
- 자식결합자
- i 태그
- padding 속성
- 일반 형제 결합자
- focus 의사클래스
- id 선택자
- sup태그
- tag html
- Checked 의사 클래스
- sub태그
- height속성
- not 의사클래스
- background-color 속성
- go live
- iframe
- 전체 선택자
Archives
- Today
- Total
so woon!
[REACT] Drag and Drop - placeholder 본문
학습일 : 2023. 04. 26
이번엔 draggable을 array로 구성해보고
placeholder를 적용해보고자 한다.
<App.tsx>
map함수를 써서 Draggable을 새로운 배열에 담아 반환해준다.
{toDos.map((toDo, index) => (
<Draggable draggableId={toDo} index={index}>
index를 넘겨주고 index={index}를 작성해주고
draggableId 또한 toDo로 주도록 하겠다.
magic을 오른쪽 클릭해서 Type Definition을 확인해보면
placeholder 라는게 있는데,
이것은 droppable이 끝날 때 두는 무언가라서
사이즈가 이상하게 변하는걸 방지해준다.
Board 안 맨 밑에 {magic.placeholder} 를 추가해주면
리스트에서 어떤 것을 빼내더라도 리스트의 사이즈는 그대로 유지하면서
안에 있는 각각의 카드를 움직일 수 있게 된다.
const toDos = ["a", "b", "c", "d", "e", "f"];
function App() {
const onDragEnd = () => {};
return (
<DragDropContext onDragEnd={onDragEnd}>
<Wrapper>
<Boards>
<Droppable droppableId="one">
{(magic) => (
<Board ref={magic.innerRef} {...magic.droppableProps}>
{toDos.map((toDo, index) => (
<Draggable draggableId={toDo} index={index}>
{(magic) => (
<Card
ref={magic.innerRef}
{...magic.draggableProps}
{...magic.dragHandleProps}
>
{toDo}
</Card>
)}
</Draggable>
))}
{magic.placeholder}
</Board>
)}
</Droppable>
</Boards>
</Wrapper>
</DragDropContext>
);
}
export default App;
실행결과
'ReactJS > 개념정리' 카테고리의 다른 글
[React] Drag and Drop - multi board 만들기 (0) | 2023.04.29 |
---|---|
[REACT] Drag and Drop - onDragEnd, 재정렬 + React.memo() (0) | 2023.04.28 |
[REACT] Drag and Drop - dragHandleProps (0) | 2023.04.26 |
[REACT] Drag and Drop2 (0) | 2023.04.25 |
[REACT] Drag and Drop1 (0) | 2023.04.25 |
Comments