diff --git a/webapp/channels/src/components/copy_url_context_menu/copy_url_context_menu.tsx b/webapp/channels/src/components/copy_url_context_menu/copy_url_context_menu.tsx index a3dab0944b..d8e92e7f9f 100644 --- a/webapp/channels/src/components/copy_url_context_menu/copy_url_context_menu.tsx +++ b/webapp/channels/src/components/copy_url_context_menu/copy_url_context_menu.tsx @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import React from 'react'; +import React, {memo, useCallback} from 'react'; import {ContextMenu, ContextMenuTrigger, MenuItem} from 'react-contextmenu'; import {FormattedMessage} from 'react-intl'; @@ -29,46 +29,52 @@ type Props = { }; } -export default class CopyUrlContextMenu extends React.PureComponent { - copy = () => { - let link = this.props.link; +const CopyUrlContextMenu = ({ + link, + siteURL, + actions, + menuId, + children, +}: Props) => { + const copy = useCallback(() => { + let siteLink = link; // Transform relative links to absolute ones for copy and paste. - if (link.indexOf('http://') === -1 && link.indexOf('https://') === -1) { - link = this.props.siteURL + link; + if (siteLink.indexOf('http://') === -1 && siteLink.indexOf('https://') === -1) { + siteLink = siteURL + link; } - this.props.actions.copyToClipboard(link); - }; + actions.copyToClipboard(siteLink); + }, [actions, link, siteURL]); - render(): JSX.Element { - const contextMenu = ( - - - - - - ); - - const contextMenuTrigger = ( - + - {this.props.children} - - ); + + + + ); - return ( - - {contextMenu} - {contextMenuTrigger} - - ); - } -} + const contextMenuTrigger = ( + + {children} + + ); + + return ( + + {contextMenu} + {contextMenuTrigger} + + ); +}; + +export default memo(CopyUrlContextMenu);