Composition vs Inheritance
文章目录

Composition vs Inheritance

不推荐使用继承

我也不推荐

示例

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

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>
  );
}