--- id: 5a24c314108439a4d4036166 title: Compose React Components challengeType: 6 isRequired: false --- ## Description
As the challenges continue to use more complex compositions with React components and JSX, there is one important point to note. Rendering ES6 style class components within other components is no different than rendering the simple components you used in the last few challenges. You can render JSX elements, stateless functional components, and ES6 class components within other components.
## Instructions
In the code editor, the TypesOfFood component is already rendering a component called Vegetables. Also, there is the Fruits component from the last challenge. Nest two components inside of Fruits — first NonCitrus, and then Citrus. Both of these components are provided for you in the background. Next, nest the Fruits class component into the TypesOfFood component, below the h1 header and above Vegetables. The result should be a series of nested components, which uses two different component types.
## Tests
```yml tests: - text: The TypesOfFood component should return a single div element. testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(TypesOfFood)); return mockedComponent.children().type() === 'div'; })(), 'The TypesOfFood component should return a single div element.'); - text: The TypesOfFood component should return the Fruits component. testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(TypesOfFood)); return mockedComponent.children().childAt(1).name() === 'Fruits'; })(), 'The TypesOfFood component should return the Fruits component.'); - text: The Fruits component should return the NonCitrus component and the Citrus component. testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(TypesOfFood)); return (mockedComponent.find('Fruits').children().find('NonCitrus').length === 1 && mockedComponent.find('Fruits').children().find('Citrus').length === 1); })(), 'The Fruits component should return the NonCitrus component and the Citrus component.'); - text: The TypesOfFood component should return the Vegetables component below the Fruits component. testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(TypesOfFood)); return mockedComponent.children().childAt(2).name() === 'Vegetables'; })(), 'The TypesOfFood component should return the Vegetables component below the Fruits component.'); ```
## Challenge Seed
```jsx class Fruits extends React.Component { constructor(props) { super(props); } render() { return (

Fruits:

{ /* change code below this line */ } { /* change code above this line */ }
); } }; class TypesOfFood extends React.Component { constructor(props) { super(props); } render() { return (

Types of Food:

{ /* change code below this line */ } { /* change code above this line */ }
); } }; ```
### Before Test
```jsx class NonCitrus extends React.Component { render() { return (

Non-Citrus:

  • Apples
  • Blueberries
  • Strawberries
  • Bananas
); } }; class Citrus extends React.Component { render() { return (

Citrus:

  • Lemon
  • Lime
  • Orange
  • Grapefruit
); } }; class Vegetables extends React.Component { render() { return (

Vegetables:

  • Brussel Sprouts
  • Broccoli
  • Squash
); } }; ```
### After Test
```js ReactDOM.render(, document.getElementById('root')) ```
## Solution
```js class Fruits extends React.Component { constructor(props) { super(props); } render() { return (

Fruits:

{ /* change code below this line */ } { /* change code above this line */ }
) } } class TypesOfFood extends React.Component { constructor(props) { super(props); } render() { return (

Types of Food:

{ /* change code below this line */ } { /* change code above this line */ }
); } }; ```