技术文献

组件通信:特殊的父传子(props-children)

2026-03-21

https://www.bilibili.com/video/BV1ZB4y1Z7o8?p=26&vd_source=fae12232d35c765816697f45f45de337

当在成对标签的子组件传值时,父组件会自动在名为children的props属性中接收

//App.js

function Son(props){
  console.log(propos)
  return <div>this is son,{props.children}</div>  //children是自动生成的名称
}

function App(){
  return (
     <div>
       <Son>this is span</span> 
     </div>
  )
}

export default App