|
1 | 1 | import { Droppable } from '@hello-pangea/dnd'; |
2 | 2 | import { Box, Typography, useTheme } from '@mui/material'; |
3 | | -import { useEffect, useRef, useState } from 'react'; |
| 3 | +import { useState } from 'react'; |
4 | 4 | import { Project, Task, TaskStatus, TaskWithIndex } from 'shared'; |
5 | 5 | import { statusNames, TaskCard } from '.'; |
6 | 6 | import { NERButton } from '../../../../../components/NERButton'; |
@@ -35,23 +35,6 @@ export const TaskColumn = ({ |
35 | 35 | const toast = useToast(); |
36 | 36 | const theme = useTheme(); |
37 | 37 |
|
38 | | - // create ref to droppable box dom node so we can measure height |
39 | | - const droppableBoxRef = useRef<HTMLElement | null>(null); |
40 | | - |
41 | | - // effectively runs once on mount because both deps (task status and callback func) are stable |
42 | | - useEffect(() => { |
43 | | - if (!droppableBoxRef.current) return; |
44 | | - |
45 | | - const droppableBox = droppableBoxRef.current; |
46 | | - const observer = new ResizeObserver(() => { |
47 | | - onHeightChange(status, droppableBox.scrollHeight); |
48 | | - }); |
49 | | - observer.observe(droppableBox); |
50 | | - |
51 | | - // cleanup func to disconnect observer when component unmounts |
52 | | - return () => observer.disconnect(); |
53 | | - }, [status, onHeightChange]); |
54 | | - |
55 | 38 | const handleCreateTask = async ({ notes, title, deadline, assignees, priority, startDate }: EditTaskFormInput) => { |
56 | 39 | try { |
57 | 40 | const task = await createTask({ |
@@ -114,7 +97,13 @@ export const TaskColumn = ({ |
114 | 97 | <Box |
115 | 98 | ref={(droppableBox: HTMLElement | null) => { |
116 | 99 | droppableProvided.innerRef(droppableBox); // give dnd lib access to dom node |
117 | | - droppableBoxRef.current = droppableBox; // give ourselves access to dom node |
| 100 | + if (!droppableBox) return; |
| 101 | + |
| 102 | + const observer = new ResizeObserver(() => { |
| 103 | + onHeightChange(status, droppableBox.scrollHeight); |
| 104 | + }); |
| 105 | + observer.observe(droppableBox); |
| 106 | + return () => observer.disconnect(); |
118 | 107 | }} |
119 | 108 | {...droppableProvided.droppableProps} |
120 | 109 | className={snapshot.isDraggingOver ? ' isDraggingOver' : ''} |
|
0 commit comments