--- id: 5a24c314108439a4d4036166 title: Compose React Components challengeType: 6 isRequired: false videoUrl: '' localeTitle: 撰写反应组件 --- ## Description
随着挑战继续使用更复杂的组合与React组件和JSX,有一点需要注意。在其他组件中渲染ES6样式类组件与渲染您在最后几个挑战中使用的简单组件没有什么不同。您可以在其他组件中呈现JSX元素,无状态功能组件和ES6类组件。
## Instructions
在代码编辑器中, TypesOfFood组件已经在呈现一个名为Vegetables的组件。此外,还有最后一项挑战中的Fruits成分。将两种成分NonCitrus Fruits - 首先是NonCitrus ,然后是Citrus 。这两个组件都是在后台为您提供的。接下来,将Fruits类组件嵌入到TypesOfFood组件中,位于h1标题下方和Vegetables上方。结果应该是一系列嵌套组件,它们使用两种不同的组件类型。
## Tests
```yml tests: - text: TypesOfFood组件应返回单个div元素。 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: TypesOfFood组件应返回Fruits组件。 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: Fruits组件应返回NonCitrus组件和Citrus组件。 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: TypesOfFood组件应返回Fruits组件下面的Vegetables组件。 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 console.info('after the test'); ```
## Solution
```js // solution required ```