gpt4 book ai didi

javascript - 每个 child 都有独特的 "key"属性

转载 作者:行者123 更新时间:2023-11-28 11:14:46 25 4
gpt4 key购买 nike

我收到此警告:

Warning: Each child in a list should have a unique "key" prop.

render() {
const exercises = this.state.Exercises.map(exercise => {
return (
<View>
<Text style={{ fontSize: 15 }}>Id: {exercise.Id} </Text>
<Text style={{ fontSize: 15 }}>Ripetizioni: {exercise.Reps}</Text>
<Text style={{ fontSize: 15 }}>Note: {exercise.Notes}</Text>
<TouchableOpacity
style={[styleButton.button, styleButton.buttonOK]}
onPress={() => this.checkAttività(exercise.Id)}
>

如何解决?

最佳答案

您应该传递返回内容的 key ,例如:

    const exercises = this.state.Exercises.map(exercise => {
return (
<View key={`${exercise.Id}`}>
<Text style={{ fontSize: 15 }}>Id: {exercise.Id} </Text>
<Text style={{ fontSize: 15 }}>Ripetizioni: {exercise.Reps}</Text>
<Text style={{ fontSize: 15 }}>Note: {exercise.Notes}</Text>
<TouchableOpacity
style={[styleButton.button, styleButton.buttonOK]}
onPress={() => this.checkAttività(exercise.Id)}
>
)
})

编辑:React期望键是一个字符串

关于javascript - 每个 child 都有独特的 "key"属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57197064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com