Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
KnowledgeHut upGradKnowledgeHut upGradBackend Development Bootcamp
  • Self-Paced
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

A Beginner’s Guide React Props [With Syntax]

Updated on 23 November, 2022

5.37K+ views
7 min read

React is an MIT-licensed open-source JavaScript library that is used for designing interactive UI for applications. It is a component-based declarative, flexible, and efficient library, making the lives of developers easier. Since it is a component-based library, it divides UI into several individual pieces known as components. These components need to communicate with each other to function appropriately, and that’s when the React props come into the picture.

Check out our free courses to get an edge over the competition. 

What are React Props?

The word “Props” is a keyword in the React library that means properties. They are also sometimes referred to as a global variable or object in React components. React props are similar to arguments in HTML. Some things worth noting about React props are that they always flow in uni-direction, and the data within them are read-only. This makes them immutable, meaning the data flowing from one component cannot be changed in the other. We can understand this with an example of a pure and impure function.

Check out upGrad’s Advanced Certification in DevOps 

This is a pure function as it will always give the same output for the same inputs:

function prod(a, b) {

return a * b;

}

This is an impure function as it is manipulating its own input:

function deposit(account, amount){

account.total += amount;

}

Since React props are immutable, the components need to operate as pure functions. That’s the only strict rule in the flexible React library.

The Syntax for Passing and Accessing React Props

As mentioned earlier, React props are similar to HTML arguments, and hence to pass or add any props to a component, we can do it similar to passing HTML attributes.

Syntax:

<component_name props_name = “value” />

In the above syntax, ‘component_name’ is the name of the component to which we need to pass props, props_name is the props’ name, and value is the props value.

We can access any props from within the component’s class.

Check out upGrad’s Full Stack Development Bootcamp (JS/MERN)

Syntax:

this.props.props_name;

In the above syntax, this.props is a global object that is used to access any props from within the component’s class, and the props_name is the name of the React props that we want to access.

How to Use React Props?

There are two different ways to use immutable React props data in any component. These two ways are by adding props to the reactDom.render() function in the main file or by adding data as default props in the component itself. Here’s how to use React props in both the ways:

Using React Props From react.Dom.render() Function

First we need to add props in the component file.

import React from ‘react’; //importing the React library

class Example extends React.component { /* example is the component name which is extending React component class’ properties */

render() {

return (

<div>

<h2>{this.props.firstProp} in h2</h2>

<h3>{this,props.secondProp} in h3</h3>

</div>

);

}

}

export default Example; //exporting the component

Now we need to add value to props via reactDom.render() function in the main file and access it from there.

import React from ‘react’;

import ReactDom from ‘react-dom’;

import Example from ‘./Example.jsx’;

ReactDom.render(<Example firstProp = “This is the firstProp” secondProp = “This is the secondProp”/>, document.getElementById(‘example’));

export default Example;

Results:

This is the firstProp in h2

This is the secondProp in h3

Using React Props With Default Props in Component Constructor

Add props and their values in the component file.

import React from ‘react’; //importing the React library

class Example extends React.component { /* example is the component name which is extending React component class’ properties */

render() {

return (

<div>

<h2>{this.props.firstProp}</h2>

<h3>{this,props.secondProp}</h3>

</div>

);

}

}

Example.deafultProps = {

firstProp: “This is the firstProp”,

secondProp: “This is the secondProp”

}

export default Example; //exporting the component

Accessing the React props from the main file.

import React from ‘react’;

import ReactDom from ‘react-dom’;

import Example from ‘./Example.jsx’;

ReactDom.render(<Example/>, document.getElementById(‘example’));

The outputs for this will be similar to reactDom.render() function usage, except that this time it is done with the help of default props.

Check out: Vue vs React: Difference Between Vue and React

How to Pass React Props From One Component to Another

The major use of React props is to pass data between components in React. The following example will help us understand how data is passed.

import React from ‘react’;

class Fruit extends React.Component {

render() {

return <h4>I am {this.props.name} in h4</h4>

}

}

class Question extends React.Component {

render() {

return (

<div>

<h3>Which Fruit are you? In h3</h3>

<Fruit name = “Mango” /> //Creating props and assigning a value

</div>

);

}

}

ReactDom.render(<Question />, document.getElementById(‘fruit’));

This will give the following output:

Which Fruit are you? In h3

I am Mango in h4

Using State and Props Together

As we all know that React is a dynamic language, and its flexibility is it’s USP. Hence, using React props all alone is not enough in developing applications. This issue is solved with the help of the state. The state is another React feature that is used for managing data. Let’s see how we can combine React props and state to make our application more interactive and dynamic.

import React from ‘react’;

class Car extends React.Component {

constructor(props) {

super(props);

this.state = {

firstCar: “This is a Mercedes-Benz! In h2”, //assigning value to state

secondCar: “This is a BMW! In h3” //assigning value to state

}

}

render() {

return (

<div>

<FirstCar firstProp = {this.state.firstCar}/> //assigning value to props

<SecondCar secondProp = {this.state.secondCar}/> //assigning value to props

</div>

);

}

}

class FirstCar extends React.Component {

render() {

return (

<div>

<h2>{this.props.firstProp}</h2>

</div>

);

}

}

class SecondCar extends React.Component {

render() {

return (

<div>

<h3>{this.props.secondProp}</h3>

</div>

);

}

}

export default Car;

Now, we need to access data from the main file.

import React from ‘react’;

import ReactDOM from ‘react-dom’;

import Car from ‘./Car.jsx’;

ReactDOM.render(<Car />, document.getElementById(‘car’));

The result:

This is a Mercedes-Benz! In h2

This is a BMW! In h3

Also Read: Difference Between Node JS and React JS

Summing it up

The combination of both React props and the state for managing data in the React makes it one of the most useful JavaScript libraries. There are tons of React project ideas out there, and only the developers can give life to them. Therefore, there is an excellent demand for ReactJS developers and an increase in their salary.

If the idea of helping businesses to create applications and working on numerous React projects to get a huge income excites you, then it is time to take action before it gets too late. You can take online courses offered by upGrad to learn everything about React and become a full-stack software developer.

If you’re interested to learn more about react, full-stack development, check out upGrad & IIIT-B’s PG Diploma in Full-stack Software Development which is designed for working professionals and offers 500+ hours of rigorous training, 9+ projects, and assignments, IIIT-B Alumni status, practical hands-on capstone projects & job assistance with top firms.

Frequently Asked Questions (FAQs)

1. How can I use PHP for app development?

PHP is a flexible programming language that can be applied to a wide range of app development projects. It features a straightforward syntax that makes it simple to pick up, and it can be used for both back-end and front-end development. A number of PHP frameworks are also available, which can make development easier and faster. It may also be used to create mobile apps utilizing the PhoneGap framework, which is built on PHP. Finally, PHP is a widely used web development language, with a variety of frameworks and tools for building dynamic and responsive websites.

2. What is Angular?

Angular is a mobile and desktop web application development framework. It's a TypeScript-based JavaScript framework. Google and the Angular team are in charge of its upkeep. YouTube for Mobile, Google AdWords, and the Google I/O app have all been developed using this. In the same way, Angular can be used to build desktop applications.

RELATED PROGRAMS