Нужна помощь в копировании в буфер обмена в Safari(ios, mac и тд) JavaScript(React) Подкажите возможно кт то сталкивался с такой проблемой

function App() {


  const copyToClipboard = (textToCopy: string) => {

    var el: any = document.createElement('textarea');
    el.value = textToCopy;
    el.setAttribute('readonly', '');
    el.style = { position: 'absolute', left: '-9999px' };
    document.body.appendChild(el);

    if (navigator.userAgent.match(/ipad|ipod|iphone/i)) {
      // save current contentEditable/readOnly status
      var editable = el.contentEditable;
      var readOnly = el.readOnly;

      // convert to editable with readonly to stop iOS keyboard opening
      el.contentEditable = true;
      el.readOnly = true;

      // create a selectable range
      var range = document.createRange();
      range.selectNodeContents(el);

      // select the range
      var selection: any = window.getSelection();
      selection.removeAllRanges();
      selection.addRange(range);
      el.setSelectionRange(0, 999999);

      // restore contentEditable/readOnly to original state
      el.contentEditable = editable;
      el.readOnly = readOnly;
    } else {
      el.select();
    }

    document.execCommand('copy');
    document.body.removeChild(el);


  }

  useEffect(() => {
      globalStote.getValue();
  }, [])


  useEffect(() => {
    if (globalStore.value) {
      copyToClipboard(globalStore.value);
    }
  }, [globalStore.value]);

  
  return (
    <div className="App">
      <header className="App-header">
      <p>{globalStote.value && <span>{globalStore.value}</span>}</p>
      </header>
    </div>
  );
}

export default App;


Ответы (0 шт):