title: Loading javascript tag into react component
body: <p>I'm trying to load a <a href="https://www.tradingview.com/widget/" rel="nofollow noreferrer">Trading View Widget</a> inside a react component. I tried using _dangerouslySetInnerHTML, however, it doesn't run the javascript code. </p>
  
  <p>I also tried this:</p>
  
  <pre><code>import React from 'react';
  
  export default class TradingView extends React.Component{
  
    constructor(props){
      super(props);
    }
  
    componentDidMount() {
      const tradingViewCode = '&lt;!-- TradingView Widget BEGIN --&gt;&lt;script type="text/javascript" src="https://d33t3vvu2t2yu5.cloudfront.net/tv.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;new TradingView.widget({"autosize": true,"symbol": "BITFINEX:BTCUSD","interval": "D","timezone": "America/New_York","theme": "White","style": "1","locale": "en","toolbar_bg": "#f1f3f6","enable_publishing": false,"hide_top_toolbar": true,"save_image": false,"hideideas": true});&lt;/script&gt;&lt;!-- TradingView Widget END --&gt;';
      new Function(tradingViewCode)();
    }
  
    render(){
      return (
        &lt;noscript /&gt;
      );
    }
  }
  </code></pre>