美文网首页
Composition vs Inheritance

Composition vs Inheritance

作者: bestCindy | 来源:发表于2020-08-15 10:59 被阅读0次
function FancyBorder(props) {
  return (
    <div>
      { props.children }
    </div>
  );
}

function WelcomeDialog() {
  return (
    <FancyBorder>
      <h1>
        Welcome
      </h1>
      <p>
        Thank you for visiting out spacecraft!
      </p>
    </FancyBorder>
  )
}
  • Anything inside the <FancyBorder> JSX tag gets passed into the FancyBorder component as a childern prop. Since FancyBorder renders {props.children} inside a <div>, the passed elements appear in the final output
  • Below is another way instead of using children
function SplitPane(props) {
  return (
    <div>
      <div>
        { props.left }
      </div>
      <div>
        { props.right }
      </div>
    </div>
  );
}

function App() {
  return (
    <SplitPane left={<Contacts />} right= {<Chat />} />
  );
}

相关文章

网友评论

      本文标题:Composition vs Inheritance

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