相关疑难解决方法(0)

为什么JSX道具不应该使用箭头函数或绑定?

我正在使用我的React app运行lint,我收到此错误:

error    JSX props should not use arrow functions        react/jsx-no-bind
Run Code Online (Sandbox Code Playgroud)

这就是我正在运行箭头功能(内部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>
))}
Run Code Online (Sandbox Code Playgroud)

这是一个应该避免的不良做法吗?什么是最好的方法呢?

javascript jsx ecmascript-6 reactjs arrow-functions

92
推荐指数
5
解决办法
4万
查看次数

标签 统计

arrow-functions ×1

ecmascript-6 ×1

javascript ×1

jsx ×1

reactjs ×1