美文网首页
React 中的 this.props.children 用法

React 中的 this.props.children 用法

作者: wlianfu | 来源:发表于2016-11-30 13:24 被阅读1515次
class RootContent extends React.Component{
    constructor(props){
        super(props);
    }
    render(){
        return (
            <div className='divider'>
                {this.props.children}
            </div>
        );
    }
}
class RootChild extends React.Component{
    constructor(props){
        super(props);
    }
    render(){
        return (
         <RootContent>
             <p>Hello, React</p>
             <p>Hello, Redux</p>
             <p>Hello, Facebook</p>
             <p>Hello, Google</p>
             </RootContent>
         );
     }
 }
 ReactDOM.render(
     <RootChild />,
     document.querySelector('#root')
 );

相关文章

网友评论

      本文标题:React 中的 this.props.children 用法

      本文链接:https://www.haomeiwen.com/subject/tectmttx.html