Composition vs Inheritance2017-10-21 21:06

Composition vs Inheritance

不推荐使用继承

我也不推荐

示例

Anything inside the <FancyBorder> JSX tag gets passed into the FancyBorder component as a children prop.


function FancyBorder(props) {
  return (
    <div className={'FancyBorder FancyBorder-' + props.color}>
      {props.children}
    </div>
  );
}


function WelcomeDialog() {
  return (
    <FancyBorder color="blue">
      <h1 className="Dialog-title">
        Welcome
      </h1>
      <p className="Dialog-message">
        Thank you for visiting our spacecraft!
      </p>
    </FancyBorder>
  );
}
Powered by Remix
|
Designed by szhshp
|
Copyright © szhshp 2022