Rendering two Elements exercise

Please try to increase the resolution of the video when playing so that it is clearer for you to read the text.

Than you Malik, I think that will help

1 Like
<>
<HelloMessage name="Zsolt" /><HelloMessage name="Sarah" />
</>```
1 Like
 <div> 
        <HelloMessage name="Zsolt"/> <HelloMessage name="Sarah"/>
    </div>,
   document.getElementById('root')

);

1 Like

ReactDOM.render(

        <><HelloMessage name="Zsolt" /><HelloMessage name="Sarah" /></>,
        document.getElementById('root')

);

1 Like
class HelloMessage extends React.Component {
  render() {
    return (
      <div>
        Hello {this.props.name}
      </div>
    );
  }
}

ReactDOM.render(
  <>
    <HelloMessage name="Zsolt"/>
    <HelloMessage name="Sarah"/>
  </>,
  document.getElementById("root")
);
1 Like

<HelloMessage name="Zsolt"/><HelloMessage name="Sarah"/>

can be rendered as following -

ReactDOM.render(
<>
<HelloMessage name="Zsolt"/>
<HelloMessage name="Sarah"/>
</>,
document.getElementById('root'));
1 Like
<meta charset="UTF-8" />

<title>Hello World</title>

<script src="https://unpkg.com/react@17/umd/react.development.js"></script>

<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>

<!-- Don't use this in production: -->

<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<div id="root"></div>

<script type="text/babel">

/*  ReactDOM.render(

    <h1>Hello, world!</h1>,

    document.getElementById('root')

  );

  */

  class HelloMessage extends React.Component {

render() {

return (

  <div>

    

    Hello, {this.props.name}

  </div>

);

}

}

var names =

  •          <HelloMessage name="TEamo" /></li>
    

    ReactDOM.render( names,

    document.getElementById(‘root’)

    );

    </script>
    
  • 1 Like
    class HelloMessage extends React.Component {
    
      render() {
    
        return (
    
          <div>
    
            
    
            Hello, {this.props.name}
    
          </div>
    
        );
    
      }
    
    }
    
    var names = <li key = "unique"><HelloMessage name="Taylor"/>
    
                 <HelloMessage name="TEamo" /></li>
    
    ReactDOM.render(  names,
    
      
    
      document.getElementById('root')
    
    );
    
        </script>
    
     
    
      </body>
    
    </html>
    
    1 Like
    **<HelloMessage name="Zsolt" /><HelloMessage name="Sarah" />**
    **<><HelloMessage name="Zsolt" /><HelloMessage name="Sarah" /></>**
    

    As per the console hint, jsx fragments were added

    1 Like

    Code gave me a fragment error. using the suggestions from Babel i was able to use the code below to print both messages.

    ReactDOM.render( React.createElement(React.Fragment, null,

    React.createElement(HelloMessage, {

    name: "Corey"
    

    }),

    React.createElement(HelloMessage, {

    name: “Sarah”

    })), document.getElementById(‘root’));

    1 Like
    ReactDOM.render(
      <>
      <HelloMessage name= "Zsolt"/>
      <HelloMessage name= "Sarah"/>
      </>,
      document.getElementById("root")
    );
    
    1 Like
    <>
      <HelloMessage name="Zsolt" />
      <HelloMessage name="Sarah" />
      
      </>
    

    “use strict”;

    /#PURE/
    React.createElement(React.Fragment, null, /#PURE/React.createElement(HelloMessage, {
    name: “Zsolt”
    }), /#PURE/React.createElement(HelloMessage, {
    name: “Sarah”
    }));

    1 Like
    ReactDOM.render(
     (<div>
      {<HelloMessage name="Kiko" />} {<HelloMessage name="NAME" />}
    
      </div>),
      
      document.getElementById('root')
    );```
    1 Like

    It looks like ReactJS is going to let me send an array of components to the render() method. The segment below allows for rendering multiple instances of a react component with a single render() call.

    ReactDOM.render(
            [<HelloMessage name="David"/>,
            <HelloMessage name="Arlyn"/>],
            document.getElementById('root')
          );
    
    1 Like

    Use a JSX fragment, by putting both of the calls inside empty elements, known as fragments:

            ReactDOM.render(
                <>
                <HelloMessage name = "Jack"/>
                <HelloMessage name = "Jason"/>
                </>,
                document.getElementById('root')
            );
    
    2 Likes
    <div id="root"></div>
    
      <script type="text/babel">
    
        class HelloMessage extends React.Component {
          render() {
            return (
              <div>
                <label htmlFor="name-field" className="mr-auto">Name: </label>
                <input type="text" id="name-field" />
                Hello, {this.props.name}!
              </div>
            );
          };
        };
    
        ReactDOM.render(
          <div>
            <HelloMessage name="Alejandra" />
            <HelloMessage name="Carlos" />
          </div>,
    
          document.getElementById('root'),
        );
    
      </script>
    
    1 Like
    <body>
        <div id="root"></div>
        <script type="text/babel">    
            class HelloMessage extends React.Component {
                render() {
                    return (
                    <div>
                        <label htmlFor="name-field" className="mr-auto">Name: </label>
                        <input type="text" id="name-field"/>
                        Hello {this.props.name}
                    </div>
                    );
                }
            }
            ReactDOM.render(
                <React.Fragment><HelloMessage name="gcrypto" /><HelloMessage name="gcrypta" /></React.Fragment>,
                document.getElementById('root')
            );
        </script>
      </body>
    
    1 Like
        <div id="hello3"></div>
        <script type="text/babel">
            class HelloMessage extends React.Component {
                render() {
                    return(
                        <div>Hello, {this.props.name}!</div>
                    );
                }
            }
    
            ReactDOM.render(
                <div><HelloMessage name="Cas" /><HelloMessage name="NWK" /></div>,
                document.getElementById("hello3")
            );
        </script>
    
    
    1 Like

    Rendering Two Elements Exercise Proposed Solution

    Here is my proposed solution.

    ReactDOM.render(
               <><HelloMessage name= "Mikal" />
                <HelloMessage name= "Sara" /> </>,
                document.getElementById('rooty')
            )
       
    
    1 Like