title: Handling onClick of a <a> tag inside of dangerouslySetInnerHTML/regular html
body: <p>I am currently writing a reddit client inside of ReactJS plus electron. I am simply doing this to understand apis better and to understand programming a large scale program. However I am becoming stuck when trying to render markdown. I have imported markdown to jsx libraries but none of them (unless I am using them wrong) have allowed me to properly convert the reddit markdown into a component I can work with.</p>
  
  <p>For example from the reddit api, I receive a comment like this:
     Hi mi name is John Doe, and I want you guys to check out [Reddit](<a href="http://www.reddit.com" rel="nofollow noreferrer">http://www.reddit.com</a>) Also don't be afraid to check out [Google](<a href="http://www.google.com" rel="nofollow noreferrer">http://www.google.com</a>)</p>
  
  <p>Now I have tried using npm modules that convert markdown into jsx, this works and will render the markdown, but I need to be able to interact with the onClick methods. Simple because this is running in an electron window, and navigating the whole browser window will navigate away from my program. Current I have it working with the following code, but this is very slow and calls the webview over 100 times.</p>
  
  <pre><code>...
  // On click of an a, this gets called a couple hundred times. :(
  componentDidMount() {
  var self = this;
  $('.linkHandler a').click(function (e) {
    e.preventDefault();
    // Opens my own custom electron webview
    self.props.loadURL(e.target.href)
  })}
  ...
  render(){
  return(
       &lt;div className="linkHandler"&gt;
           {&lt;ReactMarkdown source={comment.body} /&gt;}
  &lt;/div&gt;
  )
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I just want to be able to add an onClick handler to all of the  tags in my markdown. Reddit also supplies the html of the markdown already, but alas I am still in the same spot. With the html version I also tried doing the following:</p>
  
  <pre><code>onClick(){
      console.log('onClick Called');
  }
  ...
  getHTMl(){
      // Quickly tpyed this from memory, just keep in mind the original replaced every &lt;a with &lt;a onClick="" 
      return comment.body_html.replace(/&lt;a/g,'&lt;a onClick="' + this.onClick + '"');
  }
  ...
  render(){
  return(
       &lt;div setInnerHTMLDangerously={{"__html":this.getHTML()}}
  )
  }
  
  
  
    }
  </code></pre>
  
  <p>Tried adding () to the onClick but it gets called (100s of times) before clicking the button. The way it is now, it returns error: null reference (or something like that) in the console on click.</p>