--- id: 5a24c314108439a4d4036167 title: Render a Class Component to the DOM challengeType: 6 isRequired: false --- ## Description
You may remember using the ReactDOM API in an earlier challenge to render JSX elements to the DOM. The process for rendering React components will look very similar. The past few challenges focused on components and composition, so the rendering was done for you behind the scenes. However, none of the React code you write will render to the DOM without making a call to the ReactDOM API. Here's a refresher on the syntax: ReactDOM.render(componentToRender, targetNode). The first argument is the React component that you want to render. The second argument is the DOM node that you want to render that component within. React components are passed into ReactDOM.render() a little differently than JSX elements. For JSX elements, you pass in the name of the element that you want to render. However, for React components, you need to use the same syntax as if you were rendering a nested component, for example ReactDOM.render(<ComponentToRender />, targetNode). You use this syntax for both ES6 class components and functional components.
## Instructions
Both the Fruits and Vegetables components are defined for you behind the scenes. Render both components as children of the TypesOfFood component, then render TypesOfFood to the DOM. There is a div with id='challenge-node' available for you to use.
## 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 render the Fruits component after the h1 element. testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(TypesOfFood)); return mockedComponent.children().childAt(1).name() === 'Fruits'; })(), 'The TypesOfFood component should render the Fruits component after the h1 element.'); - text: The TypesOfFood component should render the Vegetables component after Fruits. testString: assert((function() { const mockedComponent = Enzyme.mount(React.createElement(TypesOfFood)); return mockedComponent.children().childAt(2).name() === 'Vegetables'; })(), 'The TypesOfFood component should render the Vegetables component after Fruits.'); - text: The TypesOfFood component should render to the DOM within the div with the id challenge-node. testString: assert((function() { const html = document.getElementById('challenge-node').childNodes[0].innerHTML; return (html === '

Types of Food:

Fruits:

Non-Citrus:

Citrus:

Vegetables:

'); })(), 'The TypesOfFood component should render to the DOM within the div with the id challenge-node.'); ```
## Challenge Seed
```jsx class TypesOfFood extends React.Component { constructor(props) { super(props); } render() { return (

Types of Food:

{/* change code below this line */} {/* change code above this line */}
); } }; // change code below this line ```
### Before Test
```jsx const Fruits = () => { return (

Fruits:

Non-Citrus:

  • Apples
  • Blueberries
  • Strawberries
  • Bananas

Citrus:

  • Lemon
  • Lime
  • Orange
  • Grapefruit
); }; const Vegetables = () => { return (

Vegetables:

  • Brussel Sprouts
  • Broccoli
  • Squash
); }; ```
## Solution
```js class TypesOfFood extends React.Component { constructor(props) { super(props); } render() { return (

Types of Food:

{/* change code below this line */} {/* change code above this line */}
); } }; // change code below this line ReactDOM.render(, document.getElementById('challenge-node')); ```