Skip to content

Commit

Permalink
chore: Prevent multiple portals from being created #2025
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-mihok authored and mturoci committed Sep 6, 2023
1 parent ad785cd commit 9582558
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ui/src/copyable_text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const ClipboardCopyButton = ({ value, anchorElement, showOnHoverOnly = fa
const
timeoutRef = React.useRef<U>(),
[copied, setCopied] = React.useState(false),
btnContainerRef = React.useRef<HTMLDivElement>(document.createElement('div')),
onClick = React.useCallback(async () => {
if (!anchorElement) return
try {
Expand All @@ -105,10 +106,9 @@ export const ClipboardCopyButton = ({ value, anchorElement, showOnHoverOnly = fa
React.useEffect(() => {
if (!anchorElement) return
if (portal) {
// TODO: Prevent multiple portals from being created, e.g. when showOnHoverOnly prop changes.
ReactDOM.render(
ReactDOM.createPortal(CopyButton, anchorElement),
document.createElement('div')
btnContainerRef.current
)
}
if (showOnHoverOnly) anchorElement.classList.add(css.hover)
Expand Down

0 comments on commit 9582558

Please sign in to comment.