This lesson definitely needs a solution. The sample code in the hint section is not explained properly. This is a solution I wrote for React: Render a Class Component to the DOM lesson.
Link to the lesson: https://www.freecodecamp.org/learn/front-end-libraries/react/render-a-class-component-to-the-dom
Code explanation:
-
Add the id to the div.
-
Render Fruits component exactly after the h1.
-
Follow up that with Vegetables component.
-
Render both Fruits and Vegetables component right after those.
-
Pay attention to the
document.getElementById('node-id')
as you want to render TypesOfFood component itself.ReactDOM.render(<ComponentToRender />, targetNode)
Here targetNode is thediv
but you should call it, by getting it’s element id.
class TypesOfFood extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div id='challenge-node'>
<h1>Types of Food:</h1>
{/* change code below this line */}
<Fruits/>
<Vegetables/>
ReactDOM.render(<Fruits/>, h1)
ReactDOM.render(<Vegetables/>, h1)
{/* change code above this line */}
</div>
);
}
};
// change code below this line
ReactDOM.render(<TypesOfFood/>, document.getElementById('challenge-node'));