freeCodeCamp/guide/chinese/certifications/front-end-libraries/react/create-a-component-with-com.../index.md

38 lines
670 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Create a Component with Composition
localeTitle: 使用Composition创建一个Component
---
## 使用Composition创建一个Component
### 提示1
将要呈现的组件添加到要呈现它的组件中。
### 提示2
使用JSX自闭标记。
### 提示3
要呈现的组件是ChildComponenet它将在ParentComponent中呈现
### 解
以下将根据需要呈现ParentComponent中的ChildComponent
```javascript
class ParentComponent extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<h1>I am the parent</h1>
<ChildComponent />
</div>
);
}
};
```