Https://www.freecodecamp.org/learn/front-end-libraries/react/use-react-to-render-nested-components

Tell us what’s happening:

Your code so far


const TypesOfFruit = () => {
return (
  <div>
    <h2>Fruits:</h2>
    <ul>
      <li>Apples</li>
      <li>Blueberries</li>
      <li>Strawberries</li>
      <li>Bananas</li>
    </ul>
  </div>
);
};

const Fruits = () => {
return (
  <div>
    { /* change code below this line */ }
return <TypesOfFood />;
return < Fruits/>;
    { /* change code above this line */ }
  </div>
);
};

class TypesOfFood extends React.Component {
constructor(props) {
  super(props);
}

render() {
  return (
    <div>
      <h1>Types of Food:</h1>
      { /* change code below this line */ }

      { /* change code above this line */ }
    </div>
  );
}
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36.

Challenge: Use React to Render Nested Components

Link to the challenge:

@sulymanabdullahi you can nest a component by using code like this <YourChildComponent/> in the return statement of your parent component.
Here you need to nest TypesOfFruits component in Fruits component and Fruits component in TypesOfFood.

1 Like