Compose React Components (2)

Tell us what’s happening:

  1. In that example, i specifically don’t understand why i call the Fruits class component like this : < Fruits />
    and not like that: <Fruits.render/> which make more sense for me as i’m used to C# (like calling a static method)

Your code so far


class Fruits extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <div>
        <h2>Fruits:</h2>
        { /* change code below this line */ }
<NonCitrus/>
<Citrus/>
         { /* 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 */ }
<Fruits/>
        { /* change code above this line */ }
        <Vegetables />
      </div>
    );
  }
};

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/compose-react-components

Not to be trite, but you call it that way because that is the syntax in this language, it’s not C#

This is React and not C#. When you want to render the Fruits component, you simply write <Fruits />, because React takes care of the rendering for you based on what you specify in your render method of the component.