错误TS2322:类型'“ openDialog('https://someurl.sharepoint.com / ...')无法分配给类型'EventHandler <MouseEvent <HTMLButtonElement >>

时间:2019-07-23 09:38:05

标签: reactjs typescript button onclick render

我正试图通过react rendor方法调用Javascript函数,如下所示

        <button onClick="openDialog('https://someurl.sharepoint.com/sites/Demo/Lists/EventsCalendar/calendar.aspx')">
Office Holidays
      </button>

它给我一个错误

[15:09:24]错误-打字稿-src \ webparts \ HomeEvents \ components \ HomeEvents.tsx(69,13):错误TS2322:类型为““ openDialog('https://someurl.sharepoint.com/sites/Demo/Lists/EventsCal ...”不可分配给'EventHandler>'类型。

1 个答案:

答案 0 :(得分:1)

您以错误的方式将函数传递给onClick。您需要按以下方式更改onClick函数

 <button onClick={() => openDialog('https://someurl.sharepoint.com/sites/Demo/Lists/EventsCalendar/calendar.aspx')}>
Office Holidays
      </button>