Categories

Thursday, April 18, 2024
#919814419350 therichposts@gmail.com
Reactjs

How to merge two components in reactjs?

merge two components in reactjs

Hello, welcome to therichpost.com. In this post, I will tell you, How to merge two components in reactjs? Reactjs is a Javascript Library to build user interface. Now I am also learning Reactjs these day because of my passion to learn new things.

In this post, we will merge two components and render combine output.

 Here is the working and tested code for merging two components in reactjs in index.js file:
import React from 'react';
import ReactDOM from 'react-dom';

//Component1
class Hello extends React.Component{
  render()
  {
    return (
      <h1>Hello</h1>
    )
  }
}

//Component2
class World extends React.Component{
  render()
  {
    return (
      <p>World</p>
    )
  }
}

//Merging Components
class HelloWorld extends React.Component{
  render()
  {
    return (
      <section>
      <Hello />
      <World />
      </section>
    )
  }
}

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

 

 merging-components-reactjs

if you have any query related to this post then please comment below.

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.