How to use Component in React JS?

Oct 11, 2022 . Admin

Hello Friends,

This post will give you an example of how to use component in react js. We will look at an example of use component in react js. This tutorial will give you a simple example of create component in react js. I explained simply about react js create component. So, let's follow few step to create an example of react js create component example.

This example is how to use component in react js. I will explain in component work in react js.

Components are like functions that return HTML elements.

So, let's start following example:

Step 1: Create React JS App

In this step, open your terminal and execute the following command on your terminal to create a new react app:

npx create-react-app reactjs-my-example
Step 2: Create Welcome.jsx src/Welcome.jsx
import React from 'react';

// create Welcome component 
function Welcome(){
    return(
        <h1> Welcome to Mywebtuts.com </h1>
    )
}

export default Welcome;
Step 3: Update index.js

Then after this component use in index.js file

src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import Welcome from './Welcome';

ReactDOM.render(
    // call Welcome component
    <>
        <Welcome/>
    </>>
    document.getElementById("root")
); 
Run React JS App: Output:

I hope it can help you...

#React JS