How to use Props in React JS?

Oct 12, 2022 . Admin

Hello Friends,

In this tutorial, I will show you how to use props in react js. This tutorial will give you a simple example of use props in react js. In this article, we will implement the use of props in reactjs. We will use use props react js example. So, let's follow a few step to create an example of react js use props.

In this example how to use props in react js. React js is provide to user to make defualt function props. I will explain simply used to props in react js.

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 index.js file src/index.js
import React from "react";
import ReactDOM from "react-dom/client";

function Welcome(props){
    // print props value
    return (
        <div>
            <h1>Helloo { props.name } </h1>
        </div>
    );
}

function App(){
    return (
        // create props
        <div>
            <Welcome name="Mywebtuts.com" />
        </div>
    );
}

const root = ReactDOM.createRoot(document.getElementById('root'));

root.render(<App />);
Run React JS App:
npm start

Output:

I hope it can help you...

#React JS