#6 Trello
๊นํ๋ธ
#6.2 Drag and Drop part One
react-beautiful-dnd
์๋ ๋งํฌ์ ๊ฐ์ด Drag&Drop ๊ธฐ๋ฅ์ผ๋ก ๋ฆฌ์คํธ๋ฅผ ์ฎ๊ฒจ ์์ ํ ๋ ์ ์ฉํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
DragDropContext โ ๋ด๋ถ์ ์์ด์ผ ์๋ํจ
Droppable โ ๋๋กญ : dnd ๊ธฐ๋ฅ์ด ์ค์ ๋ก ์๋ํ ๋ฒ ์ด์ค, ํจ์ํ์ผ๋ก ์์ฑํด์ผํจ
Draggable โ ๋๋๊ทธ : Drag ๊ธฐ๋ฅ, ํจ์ํ์ผ๋ก ์์ฑํด์ผํจ
<DragDropContext onDragEnd={onDragEnd}>
<div>
<Droppable droppableId='one'>
{() =>
<ul>
<Draggable draggableId='first' index={0}>
{() => <li>One</li>}
</Draggable>
<Draggable draggableId='seound' index={1}>
{() => <li>Two</li>}
</Draggable>
</ul>}
</Droppable>
</div>
</DragDropContext>
npm i react-beautiful-dnd
npm i --save-dev @types/react-beautiful-dnd
#6.3 Drag and Drop part Two
Droppable & Draggable์ ๋ด๋ถ props
innerRef ์์ฑ์ ๊ธฐ๋ฐ์ผ๋ก ์ํ๋๋ค.
dragHandleProps ํน์ ์์ญ์ ํตํด์๋ง ๋๋๊ทธ๋ฅผ ๊ฐ๋ฅํ๊ฒํจ
draggableProps ๋๋๊ทธํ ์์ญ ์ง์
<DragDropContext onDragEnd={onDragEnd}>
<div>
<Droppable droppableId='one'>
{(magic) =>
<ul ref={magic.innerRef} {...magic.droppableProps}>
<Draggable draggableId='first' index={0}>
{(provided) => <li ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps} >One</li>}
</Draggable>
<Draggable draggableId='seound' index={1}>
{(provided) => <li ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps} >Two</li>}
</Draggable>
</ul>}
</Droppable>
</div>
</DragDropContext>
#6.4 Styles and Placeholders
placeholder
Draggable ์์๋ฅผ ๋๋๊ทธํ๋๋์ Droppable์ position:fixed๋ฅผ ์ ์ฉํด ํฌ๊ธฐ๊ฐ ์ค์ด๋๋ ๊ฒ์ ๋ฐฉ์งํ๋ค.
#6.5 Reordering
recoil ๊ธฐ๋ณธ ์ธํ
onDragEnd ๋๋๊ทธ๊ฐ ์ข ๋ฃ๋์๋์ ์ธํ
.type - ๋๋๊ทธ๋ Draggable์ type
.source - ๋๋๊ทธ ์์ ์์น
.destination - ๋๋๊ทธ ์ข ๋ฃ ์์น, ์์๊ณผ ๊ฐ์ ์์น๋ผ๋ฉด null
splice(a, b, c) - a ์์์์น b ์ง์ธ๊ฐ์ c ์ถ๊ฐํ ๋ด์ฉ
#6.6 Reordering Two
onDragEnd, splice๋ก ๋ชฉ๋ก ์์ ๊ตฌํ ์๋ฃ
li๋ก ๋ชฉ๋ก ๊ตฌ๋ถ์ key๋ฅผ ์ ๋๋ก ์์ฑํด์ผ ํ๋ค.
์ผ๋ฐ์ ์ผ๋ก draggableId๋ฅผ key๋ก ์ด์ฉํ๋ค.
โ index๋ฅผ key๋ก ์ฌ์ฉํ ๋ ๊ฒฝ๊ณ ํ์ง ์๊ธฐ ๋๋ฌธ์ & index๋ฅผ key๋ก ์ฌ์ฉํ๋ฉด ์์๊ฐ ๋ค๋ฐ๋๋ฉด์ ์ข์ง์์ ๊ฒฐ๊ณผ๋ฅผ ์ด๋ํ๋ค
#6.7 Performance
์ฝ๋ ์ ๋ฆฌ
Drag๋ก ์ด๋ํ๋ฉด ๋ชจ๋ ๋ฆฌ์คํธ๊ฐ ์๋ก ๋ ๋๋ง๋๋๊ฒ ๋์ ๋ณด์ โ ๋ถ๋ชจ์ ์ํ๊ฐ ๋ณ๊ฒฝ๋๋ฏ๋ก ๋ชจ๋ ์์ ์์๋ค์์ ๋ถํ์ํ ๋ ๋๋ง์ด ๋ฐ์ํจ
โ React Memo๋ prop์ด ๋ณ๊ฒฝ๋์ง ์์ผ๋ฉด ์์๋ค์ด ๋ ๋๋ง ๋์ง ์๋๋ก ์ค์ ํจ
export default DraggableCard;
=>
export default React.memo(DraggableCard);
#6.8 Multi Boards
์ฌ๋ฌ ์ํ ๋ฐ์ค?๋ฅผ ๋ง๋ค๊ณ ์ถ๋ค.. ๊ทธ๋ฐ๋ฐ ํ๋์ recoil state์์..
{1: [], 2: [], 3: []} ๊ฐ์ ๋ฐ์ดํฐ ๊ตฌ์กฐ์ด๊ธฐ์ ๋ค์์ ๊ธฐ๋ฅ์ผ๋ก ์ํ๋ฅผ ๊ฐ์ ธ์จ๋ค.
Object.keys(obj)
๊ฐ์ฒด์ ์์ฑ key๋ค์ ๋ฐ๋ณต๋ฌธ๊ณผ ๋์ผํ ์์๋ก ์ํ๋๋ ๋ฐฐ์ด๋ก ๋ฐํํ๋ค.
.map์ ์ด์ฉํด ๋ค์ ์ฌ๋ฌ ๊ฐ์ ์๋ฆฌ๋จผํธ๋ก ๊ตฌ๋ถํ๋ค.
#6.9 Same Board Movement
๊ฐ์ Board์์ ๋๋๊ทธํ ๋โฆ
state ๊ตฌ์กฐ๊ฐ ๋ณ๊ฒฝ๋์๊ธฐ์ ๊ทธ ๋ณํ์ ๋ง์ถฐ์ state ๊ฐ์ ์์ ํ๋ค.
ํ๋์ ์ํ ๊ทธ๋ฃน ๋ด์์ ์งํ๋จ
#6.10 Cross Board Movement
๋ค๋ฅธ Board์์ ๋๋๊ทธํ ๋โฆ
๊ทธ๋ฃน ๊ฐ์ ๋ณํ์ ์ฃผ์ํ๋ฉด์ ๊ฐ์ Board ๋ณ๊ฒฝ๊ณผ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก state ๊ฐ์ ์์ ํ๋ค.
#6.11 Droppable Snapshot
๋๋๊ทธํ ๋ ๋ง์ง๋ง ์์๊ฐ ์ฌ๋ผ์ง๋ฉด ๋์ด๊ฐ ์ฌ๋ผ์ง๋ฉด์ ์ด๋์ ์ ์ฝ์ด ์๊ธด๋ค.
display flex๋ก ์ฝ๊ฒ ์ ์ฝ์ ์์จ ์ ์์
& DroppableStateSnapshot ๋๋์ด ๋ฐ์ํ๋ ์ฅ์(Droppable)์์ ๋ค์ํ ์ ๋ณด๋ฅผ ์ป์ ์ ์์
isDraggingOver: boolean
ํ์ฌ ์ ํํ Draggable์ด ํน์ Droppable ์์ ๋๋๊น ๋๋์ง ์ฌ๋ถ
draggingOverWith: ?DraggabledId
Droppable ์๋ก ๋๋๊ทธํ๋ Draggable ID
draggingFromThisWith: ?DraggableId
ํ์ฌ Droppable์์ ๋ฒ์ด๋ ๋๋๊น ๋๊ณ ์๋ Draggable ID
isUsingPlaceholder: boolean
placeholder๊ฐ ์ฌ์ฉ๋๊ณ ์๋์ง ์ฌ๋ถ
#6.12 Final Styles
isDragging - boolean
Draggable์ด ์คํ๋๋์ง ์ฌ๋ถ
#6.13 Refs
Refs - React ์ฝ๋๋ฅผ ์ด์ฉํด HTML ์์๋ฅผ ์ง์ ํ๊ณ , ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ
beautiful-dnd ๊ฐ React ์์์ ์ ๊ทผํ ์ ์๋๋ก ๋์์ค
const ~~ = useRef()
#6.14 Task Objects
toDo ์ถ๊ฐํ๋ ๊ธฐ๋ฅ์ถ๊ฐ
atoms์์ state data๋ฅผ ์ ๋นํด์ผํจ
โ draggableId ๊ฐ์ ์ถ๊ฐ์ ์ผ๋ก ์ ๊ณตํด์ผํจ
&
React Hook Form
...
const {register, handleSubmit, setValue, getValue} = useForm<IForm>
...
#6.15 Creating Tasks
id ๊ฐ์ ๊ณ ์ ํ data๋ก ์ ๊ณต(Date.now())ํ๋ฉด์ ์ค๋ฅ ํด๊ฒฐ
Last updated
Was this helpful?