【发布时间】:2017-05-19 14:29:29
【问题描述】:
我想将一个返回另一个函数的函数传递给 Material UI 的 onTouchTap 事件:
<IconButton
onTouchTap={onObjectClick(object)}
style={iconButtonStyle} >
<img alt={customer.name} className="object-img" src={object.avatarSrc} />
</IconButton>
但我一直遇到以下错误:
Type '{ onTouchTap: Function; style: CSSProperties; tooltip: string; children: Element; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<IconButton> & Readonly<{ children?: ReactNode; }> ...'.
如果我只是传递一个函数,点击事件就会被触发并且一切正常:
<IconButton
onTouchTap={onObjectClick}
style={iconButtonStyle} >
<img alt={customer.name} className="object-img" src={object.avatarSrc} />
</IconButton>
但是,该函数运行时传递了 event,这对我没有帮助。我需要传递一个包含数据的对象。有谁知道如何设置一个返回函数的函数,或者 onTouchTap 的处理程序或使用 typescript 做出反应的 onClick 事件?
【问题讨论】:
标签: javascript reactjs typescript material-ui