useCopying.jsx 393 B

12345678910111213141516171819
  1. import React, { useRef } from "react";
  2. export default text => {
  3. const textareaRef = useRef(null);
  4. const copyText = () => {
  5. textareaRef.current.select();
  6. document.execCommand("copy");
  7. };
  8. const hiddenTextArea = (
  9. <textarea
  10. ref={textareaRef}
  11. className="click-to-copy__textarea"
  12. value={text}
  13. readOnly
  14. />)
  15. ;
  16. return [hiddenTextArea, copyText]
  17. }