title: document.execCommand ('copy') don't work in React
body: <p>I have the function below that is called on click of a button . Everything works well, but the <code>document.execCommand ('copy')</code> simply does not work.</p>
  
  <p>If I create another button and call only the contents of <code>if</code> in a separate function, it works well.</p>
  
  <p>I have already tried calling a second function inside the first one, but it also does not work. the copy is only working if it is alone in the function.</p>
  
  <p>Does anyone know what's going on?</p>
  
  <pre><code>copyNshort = () =&gt; {
      const bitly = new BitlyClient('...') // Generic Access Token bit.ly
      let txt = document.getElementById('link-result')
  
      bitly.shorten(txt.value)
          .then((res) =&gt; {
              this.setState({ shortedLink: res.url })
  
              if (this.state.shortedLink !== undefined) {
                  document.getElementById('link-result-shorted').select() // get textarea value and select
                  document.execCommand('copy') // copy selected
                  console.log('The link has been shortened and copied to clipboard!')
                  ReactDOM.render(&lt;i className="fas fa-clipboard-check"&gt;&lt;/i&gt;, document.getElementById('copied'))
              }
              console.log('Shortened link ', res.url) // Shorted url
          })
  }
  </code></pre>