diff --git "a/React\351\235\242\351\235\242\350\247\202/\343\200\220\350\257\221\343\200\221\345\277\253\351\200\237\350\265\267\346\255\245-\347\273\204\345\220\210\344\270\216\347\273\247\346\211\277.md" "b/React\351\235\242\351\235\242\350\247\202/\343\200\220\350\257\221\343\200\221\345\277\253\351\200\237\350\265\267\346\255\245-\347\273\204\345\220\210\344\270\216\347\273\247\346\211\277.md" new file mode 100644 index 0000000..56468d5 --- /dev/null +++ "b/React\351\235\242\351\235\242\350\247\202/\343\200\220\350\257\221\343\200\221\345\277\253\351\200\237\350\265\267\346\255\245-\347\273\204\345\220\210\344\270\216\347\273\247\346\211\277.md" @@ -0,0 +1,170 @@ +--- +title: 快速起步-组合与继承 +date: 2017-4-26 13:19:51 +version: 15.5.0 +--- + +# 组合 VS. 继承 + +`React` 具有很强大的组合模型,我们推荐使用组合而不是继承来重用组件之间的代码。 + +在这一章节中,我们将思考一些React新手通常遇到的问题,并展示如何使用组合来解决它们。 + +## 容器 + +一些组件并不能提前知道它们的子集。这在通用盒子组件,如 `Sidebar` 或者 `Dialog` 上尤其常见。 + +我们推荐这类组件使用特定的 `children` 属性,将子元素传递到其输出中: + +```js{4} +function FancyBorder(props) { + return ( +
+ Thank you for visiting our spacecraft! +
++ {props.message} +
++ {props.message} +
+ {props.children} +