ReactNative解决Warning: Each child in an array or iterator should have a unique "key" prop.

今天试了一下RN项目, 报了个奇葩错误, 先上代码

//carousel.jsx
import React from 'react';

export default class CarouselList extends React.Component{
    constructor(props){
        super(props);
    }
    render(){
        var lists = this.props.lists;
        return (
            
{ lists.map(function(data,i){ return ( ) }) }
) } }
上面的组件执行会报错:

Warning: Each child in an array or iterator should have a unique “key” prop.

解决办法:循环的时候加个key={i} 虽然并没啥用,但是必须加
import React from 'react';

export default class CarouselList extends React.Component{
    constructor(props){
        super(props);
    }
    render(){
        var lists = this.props.lists;
        return (
            
{ lists.map(function(data,i){ return ( ) }) }
) } }

如果对你有帮助请给个❤️

你可能感兴趣的:(ReactNative解决Warning: Each child in an array or iterator should have a unique "key" prop.)