Skip to content

Commit ae291bb

Browse files
authored
fix: popover with react18
1 parent 5612934 commit ae291bb

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

packages/coreui-react/src/components/popover/CPopover.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,26 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
136136
useEffect(() => {
137137
if (_visible) {
138138
setMounted(true)
139+
}
139140

141+
return () => {
142+
if (popoverRef.current) {
143+
popoverRef.current.classList.remove('show')
144+
onHide && onHide()
145+
executeAfterTransition(() => {
146+
if (popoverRef.current) {
147+
popoverRef.current.style.display = 'none'
148+
}
149+
150+
destroyPopper()
151+
setMounted(false)
152+
}, popoverRef.current)
153+
}
154+
}
155+
}, [_visible])
156+
useEffect(() => {
157+
if (mounted) {
158+
// On the render after `setMounted(true)`, the popoverRef will be populated
140159
if (popoverRef.current) {
141160
popoverRef.current.classList.remove('fade', 'show')
142161
destroyPopper()
@@ -155,22 +174,7 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
155174
}
156175
}, _delay.show)
157176
}
158-
159-
return () => {
160-
if (popoverRef.current) {
161-
popoverRef.current.classList.remove('show')
162-
onHide && onHide()
163-
executeAfterTransition(() => {
164-
if (popoverRef.current) {
165-
popoverRef.current.style.display = 'none'
166-
}
167-
168-
destroyPopper()
169-
setMounted(false)
170-
}, popoverRef.current)
171-
}
172-
}
173-
}, [_visible])
177+
}, [mounted])
174178

175179
return (
176180
<>

0 commit comments

Comments
 (0)