在父组件中
import React,{FC,useState} from "react"
import Cmittem from "@/components1/cmittem"
const Cmtlist:FC<{}>=(props)=>{
const [commentList]=useState([
{ id: 1, user: '张三', content: '哈哈,沙发' },
{ id: 2, user: '李四', content: '哈哈,板凳' },
{ id: 3, user: '王五', content: '哈哈,凉席' },
{ id: 4, user: '赵六', content: '哈哈,砖头' },
{ id: 5, user: '田七', content: '哈哈,楼下山炮' }])
return (
<div>
{
commentList.map((item)=>{
return (
<Cmittem key={item.id} {...item}></Cmittem>
)
})
}
</div>
)
}
export default Cmtlist
在子组件中
import React,{FC} from "react"
type IProps={
id:number,
user:string,
content:string
}
const Cmittem:FC<IProps>=(props)=>{
return <div className="item" key="item.id">
{props.user}----{props.content}
</div>
}
export default Cmittem