Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 6dd256a

Browse files
committed
DropDown: refactor back to simpler callback
1 parent 89fe12b commit 6dd256a

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/components/DropDown/DropDown.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,16 @@ const DropDown = React.memo(function DropDown({
116116
const [measureWidth, setMeasureWidth] = useState(true)
117117

118118
// Adjust the button width if the item widths are larger than declared width
119-
const [ghostElement, setGhostElement] = useState(null)
120-
const popoverRefCallback = useCallback(
121-
el => {
122-
if (!el) {
123-
return
124-
}
125-
setGhostElement(el)
126-
},
127-
[setGhostElement]
119+
const [placeholderMinWidth, setPlaceholderMinWidth] = useState(
120+
Math.min(widthNoPx, MIN_WIDTH)
128121
)
129-
const placeholderMinWidth = useMemo(() => {
130-
if (!ghostElement) {
131-
return Math.min(widthNoPx, MIN_WIDTH)
122+
const popoverRefCallback = useCallback(el => {
123+
if (!el) {
124+
return
132125
}
133-
return ghostElement.clientWidth
134-
}, [ghostElement, widthNoPx])
135-
126+
setPlaceholderMinWidth(el.clientWidth)
127+
setMeasureWidth(false)
128+
}, [])
136129
useEffect(() => {
137130
setMeasureWidth(true)
138131
}, [vw, items])

0 commit comments

Comments
 (0)