列表中的每个子项都应该有一个唯一的“键”。支柱。检查渲染方法
你好,我对编程还很陌生,但我遇到了一个问题。我已经构建了一个带有对象数组和属性“id”的接口。我使用它(id:属性)作为我的唯一密钥,但它给了我一个错误。 这就是界面
export interface IState {
meetupsy: {
id: number
}[]
}
,这是一个列表组件,
import classes from './MeetupList.module.css'
import { IState as Props } from '../../App'
import Card from '../ui/Card'
interface IProps {
meetups: Props['meetupsy']
}
const MeetupList: React.FC<IProps> = ({meetups}) => {
const renderList = ():JSX.Element[] => {
return meetups.map((meetup) => {
return <Card>
<li key={meetup.id} className={classes.list}>
<div className={classes.image} />
</li>
</Card>
})
}
return (
<ul className={classes.render}>
{renderList()}
</ul>
)
}
export default MeetupList;
我真的很困惑它说“检查 MeetupList
的渲染方法”
Hi so I am pretty new to programming and I got kinda stuck with a problem. I've built an interface with array of objects and with property 'id'. I used it (id: property) as my Unique key but it gives me an error.
Thats's the interface
export interface IState {
meetupsy: {
id: number
}[]
}
and that's a List component
import classes from './MeetupList.module.css'
import { IState as Props } from '../../App'
import Card from '../ui/Card'
interface IProps {
meetups: Props['meetupsy']
}
const MeetupList: React.FC<IProps> = ({meetups}) => {
const renderList = ():JSX.Element[] => {
return meetups.map((meetup) => {
return <Card>
<li key={meetup.id} className={classes.list}>
<div className={classes.image} />
</li>
</Card>
})
}
return (
<ul className={classes.render}>
{renderList()}
</ul>
)
}
export default MeetupList;
I am really puzzled it says "Check the render method of MeetupList
"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此问题已回答多次。
您要迭代的每个元素都必须有一个
key
属性,该属性必须放置在最外层元素中并且必须是唯一的。This question was answered multiple times.
Each of the elements you are iterating through must have a
key
property that must be put in the outermost element and must be unique.