title: Call function on button press - react
body: <p>I'm dynamically generating some HTML and I want some &quot;events&quot; to have an onclick component that calls a simple function.  I'm working with react and typescript.</p>
  <p>This is what I'd imagine would work:</p>
  <pre><code>function add_event(day: number, month: number, events: any) {
    let event_html = &quot;&quot;;
    events[month].forEach((event: any) =&gt; {
      const event_date = new Date(event.activity_start_date);
      if (event_date.getMonth() == month &amp;&amp; event_date.getDate() == day) {
        event_html += `&lt;table&gt;&lt;td onclick='select_event()' class='event'&gt;${event.activity_name}&lt;/td&gt;&lt;/table&gt;`;
      }
    });
    return event_html;
  }
  
  function select_event(){
    console.log('selected')
  }
  </code></pre>
  <p>However, I get this error &quot;Uncaught ReferenceError: select_event is not defined
  at HTMLTableCellElement.onclick&quot;</p>
  <p>I'm guessing the problem is that the function only lives in this local tsx file and not the HTML file built by react.  How can I go about solving this?</p>