Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 每个孩子都应该有一个道具警告_Reactjs_List - Fatal编程技术网

Reactjs 每个孩子都应该有一个道具警告

Reactjs 每个孩子都应该有一个道具警告,reactjs,list,Reactjs,List,为什么我会收到这样的警告:当我在map函数中添加key时,列表中的每个孩子都应该有一个唯一的“key”道具。 const fieldsArr = effectsTextArr.map((effectsText, i) => { const style = effectsText.length === 1 ? fieldStyle1Icon : fieldStyle2Icons return (

为什么我会收到这样的警告:
当我在map函数中添加key时,列表中的每个孩子都应该有一个唯一的“key”道具。

const fieldsArr =
        effectsTextArr.map((effectsText, i) => {
                const style = effectsText.length === 1 ? fieldStyle1Icon : fieldStyle2Icons
                return (
                    <div style={style} key={i} onClick={() => playerStateContext.handleClickOnRelic(effectsArr[i], i)}>
                        {playerState.relics[i] ? effectsText : <Shiny/>}
                    </div>
                )
            }
        )
const fieldsArr=
effectsTextArr.map((effectsText,i)=>{
const style=effectsText.length==1?fieldStyle1Icon:fieldStyle2Icons
返回(
playerStateContext.handleClickOnRelic(effectsArr[i],i)}>
{playerState.遗迹[i]?效应文本:}
)
}
)
源阵列:

const effectsTextArr = [
        [<Jewel/>],
        [<Jewel/>],
        [<Coin/>, <div style={overLapStyle}><Weapon/></div>],
        [<Weapon/>],
        [<Explore/>, <div style={overLapStyle}><Text/></div>],
        [<Coin/>, <div style={overLapStyle}><Text/></div>],
        [<Coin/>],
        [<Explore/>],
        [<Draw1Card/>]
    ]
const effectsTextArr=[
[],
[],
[, ],
[],
[, ],
[, ],
[],
[],
[]
]

我是否也应该向源数组元素添加键?这样使用JSX元素是错误的吗?我使用它们来存储我在应用程序不同位置使用的图标。

effectsText
是一个JSX元素数组,它仍然需要为其分配一个唯一的键

{playerState.relics[i] ? 
     effectsText :  // here an array is passed and every elem requires a key
     <Shiny />
}
{playerState.遗迹[i]?
effectsText://此处传递一个数组,每个元素都需要一个键
}
因此,您可以映射它并分配一个键,而不是直接将其作为变量传递:

{effectsText.map((nested) => (
   <React.Fragment key={someUniqId}>{nested}</React.Fragment>
)}
{effectsText.map((嵌套)=>(
{nested}
)}

effectsText
是一个JSX元素数组,它仍然需要为其分配一个唯一的键

{playerState.relics[i] ? 
     effectsText :  // here an array is passed and every elem requires a key
     <Shiny />
}
{playerState.遗迹[i]?
effectsText://此处传递一个数组,每个元素都需要一个键
}
因此,您可以映射它并分配一个键,而不是直接将其作为变量传递:

{effectsText.map((nested) => (
   <React.Fragment key={someUniqId}>{nested}</React.Fragment>
)}
{effectsText.map((嵌套)=>(
{nested}
)}