【发布时间】:2017-05-25 07:36:10
【问题描述】:
我正在使用我的 React 应用程序运行 lint,我收到此错误:
error JSX props should not use arrow functions react/jsx-no-bind
这就是我运行箭头函数的地方(在onClick 内):
{this.state.photos.map(tile => (
<span key={tile.img}>
<Checkbox
defaultChecked={tile.checked}
onCheck={() => this.selectPicture(tile)}
style={{position: 'absolute', zIndex: 99, padding: 5, backgroundColor: 'rgba(255, 255, 255, 0.72)'}}
/>
<GridTile
title={tile.title}
subtitle={<span>by <b>{tile.author}</b></span>}
actionIcon={<IconButton onClick={() => this.handleDelete(tile)}><Delete color="white"/></IconButton>}
>
<img onClick={() => this.handleOpen(tile.img)} src={tile.img} style={{cursor: 'pointer'}}/>
</GridTile>
</span>
))}
这是一种应该避免的不良做法吗?最好的方法是什么?
【问题讨论】:
标签: javascript reactjs ecmascript-6 jsx arrow-functions