本机反应 - eslint 给出太多错误

react native - eslint give too much errors

我用 React Native 编码不是很好, 但我不断收到来自 eslint 的错误,

例如:

 {
        this.state.markers.map(marker => (
          <MapView.Marker
            coordinate={{longitude: marker.longitude, latitude: marker.latitude}}
            title={marker.title}
            description={marker.info}>
          </MapView.Marker>
        ))
      }

eslint 提供红线错误消息:Missing "key" prop for element in iteratoreslintreact/jsx-key

代码错了让我很犹豫

还有更多道具错误。

这是为什么呢?地图运行良好,有时我使用 this.props 也会出错。

有没有 eslint 的替代品或最好的?

我使用 vscode

您必须为组件数组添加键 属性,以便 React 可以正确检测到对象已更改。如果不这样做,React 只会比较之前和当前的对象引用,这可能会导致一些意外的行为和性能问题。 如果您的标记项有一个名称 属性,您可以这样做:

{
        this.state.markers.map(marker => (
          <MapView.Marker
            key={marker.name}
            coordinate={{longitude: marker.longitude, latitude: marker.latitude}}
            title={marker.title}
            description={marker.info}>
          </MapView.Marker>
        ))
}