title: React remove script when component will unmount
body: <p>How can I remove the previously added script from component when it will unmount?</p>
  
  <p>This is my code:</p>
  
  <pre><code>import React from 'react';
  
  export default class ScriptServices extends React.Component {
    constructor(props) {
      super(props);
    }
  
    componentDidMount() {
      const s = document.createElement('script');
      s.type = 'text/javascript';
      s.async = true;
      s.src = "./scriptServices.js";
      this.instance.appendChild(s);
    }
  
    componentWillUnmount() {
      // remove script
    }
  
    render() {
      return &lt;div ref={el =&gt; (this.instance = el)} /&gt;;
    }
  }
  </code></pre>