Files
freeCodeCamp/guide/english/certifications/front-end-libraries/react/compose-react-components/index.md

47 lines
907 B
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Compose React Components
---
2019-01-15 17:13:49 -05:00
# Compose React Components
2018-10-12 15:37:13 -04:00
2019-01-15 17:13:49 -05:00
## Hint
2018-10-12 15:37:13 -04:00
2019-01-15 17:13:49 -05:00
Use nested components as in the previous challenge to render components.
2018-10-12 15:37:13 -04:00
2019-01-15 17:13:49 -05:00
## Solution
2018-10-12 15:37:13 -04:00
2019-01-15 17:13:49 -05:00
The following is the solution to the challenge, where it render `Citrus` and `NonCitrus` in a component which is then rendered in another:
2018-10-12 15:37:13 -04:00
```jsx
class Fruits extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<h2>Fruits:</h2>
<NonCitrus />
<Citrus />
</div>
);
}
};
class TypesOfFood extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<Fruits />
<Vegetables />
</div>
);
}
};
```
### Relevant Links:
- [Components and Props](https://reactjs.org/docs/components-and-props.html)
- [Nested Components](http://www.reactjstutorial.net/nested-components.html)