Do all custom component classes have a self closing tag?

https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-react-part-i/modules/fecp-react-components/lessons/your-first-react-component/exercises/create-component-instance

Usually yes, React components commonly are in the format <Component /> (<Component><Component /> also works but is not preferred). That said, you can have components that are not self closing and can contain children, for example:

<Component>
  <p>I am a child!</p>
</Component>

You can access any children of a component with the props.children object, although you will learn about props later on in the course and that’ll be clearer, I’m just mentioning it for the sake of completeness. :smile:

2 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.