[Original] How to copy the ID behind the icon by clicking on it

React technology develops backend management system

The function to be implemented is to click the copy icon and copy the following ID

First, introduce copy

import copy from 'copy-to-clipboard';

Then define the method

  const spanRef = useRef(null);

  function handleCopyClick() {
    const textToCopy = spanRef.current.innerText;
    copy(textToCopy);
    message.success('复制成功!');
  }

and then call the method

<div onClick={handleCopyClick} >
	<div ref={spanRef}><CopyTwoTone />{item.meetingId}</div>
</div>

The front-end implementation effect is as shown below

 

Guess you like

Origin blog.csdn.net/yiran1919/article/details/130321489