在父组件中

    1. import React,{FC,useState} from "react"
    2. import Cmittem from "@/components1/cmittem"
    3. const Cmtlist:FC<{}>=(props)=>{
    4. const [commentList]=useState([
    5. { id: 1, user: '张三', content: '哈哈,沙发' },
    6. { id: 2, user: '李四', content: '哈哈,板凳' },
    7. { id: 3, user: '王五', content: '哈哈,凉席' },
    8. { id: 4, user: '赵六', content: '哈哈,砖头' },
    9. { id: 5, user: '田七', content: '哈哈,楼下山炮' }])
    10. return (
    11. <div>
    12. {
    13. commentList.map((item)=>{
    14. return (
    15. <Cmittem key={item.id} {...item}></Cmittem>
    16. )
    17. })
    18. }
    19. </div>
    20. )
    21. }
    22. export default Cmtlist

    在子组件中

    1. import React,{FC} from "react"
    2. type IProps={
    3. id:number,
    4. user:string,
    5. content:string
    6. }
    7. const Cmittem:FC<IProps>=(props)=>{
    8. return <div className="item" key="item.id">
    9. {props.user}----{props.content}
    10. </div>
    11. }
    12. export default Cmittem