0

I would like to understand the React code below; Specifically, I am assuming that the is rendering component of this but the "Welcome" in the snippet above refers to the "Welcome" function at the top and that the rendinring runs the function through 3 iterations, one for each name??

...

function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}

function App() {
  return (
    <div>
      <Welcome name="Sara" />
      <Welcome name="Cahal" />
      <Welcome name="Edite" />
    </div>
  );
}

ReactDOM.render(
  <App />,
  document.getElementById('root')
);

1 Answer 1

1

This is an example of Composing Components.

Components can refer to other components in their output.

This means that we can nest multiple components inside of a component. This is usually referred to as Parent/Child Components. A Parent Component can render many Child Components.

In the example you posted, they have created a functional stateless component called <Welcome />. The <App /> component is the Parent Component and it needs to render the <Welcome /> component three times, each with different data. They are using props to pass in a different name to each <Welcome /> component.

When the <App /> components render method is called, it will render the <Welcome /> component three separate times, each with their own props.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.