我正试图通过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>'类型。
答案 0 :(得分:1)
您以错误的方式将函数传递给onClick
。您需要按以下方式更改onClick
函数
<button onClick={() => openDialog('https://someurl.sharepoint.com/sites/Demo/Lists/EventsCalendar/calendar.aspx')}>
Office Holidays
</button>