🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to React Notes
Topic #23

React Props


Props are arguments passed into React components.

Props are passed to components via HTML attributes.

Note: props stands for properties.


React Props

React Props are like function arguments in JavaScript and attributes in HTML.

To send props into a component, use the same syntax as HTML attributes:

Example

createRoot(document.getElementById('root')).render(
  <Car brand="Ford" />
);

The component receives the argument as a props object:

Example

function Car(props) {
  return (
    <h2>I am a {props.brand}!</h2>
  );
}

The name of the object is props, but you can call it anything you want.

Example

function Car(myobj) {
  return (
    <h2>I am a {myobj.brand}!</h2>
  );
}

Pass Multiple Properties

You can send as many properties as you want.

Every attribute is sent to the Car component as object properties.

Example

createRoot(document.getElementById('root')).render(
  <Car brand="Ford" model="Mustang" color="red" />
);

All properties are received in the Car component inside the props object:

Example

function Car(props) {
  return (
    <h2>I am a {props.color} {props.brand} {props.model}!</h2>
  );
}

Different Data Types

React props can be of any data type, including variables, numbers, strings, objects, arrays, and more.

Strings can be sent inside quotes as in the examples above, but numbers, variables, and objects need to be sent inside curly brackets.

Example

createRoot(document.getElementById('root')).render(
  <Car year={1969} />
);

Example

let x = "Ford";

createRoot(document.getElementById('root')).render(
  <Car brand={x} />
);

Example

let x = [1964, 1965, 1966];
let y = {name: "Ford", model: "Mustang"};

createRoot(document.getElementById('root')).render(
  <Car years={x} carinfo={y} />
);

Object Props

The component treats objects like objects, and you can use the dot notation to access the properties.

Example

function Car(props) {
  return (
    <>
      <h2>My {props.carinfo.name} {props.carinfo.model}!</h2>
      <p>It is {props.carinfo.color} and it is from {props.carinfo.year}!</p>
    </>
  );
}

const carInfo = {
  name: "Ford",
  model: "Mustang",
  color: "red",
  year: 1969
};

createRoot(document.getElementById('root')).render(
  <Car carinfo={carInfo} />
);

Array Props

Array props can be accessed using the indexes.

Example

function Car(props) {
  return (
    <h2>My car is a {props.carinfo[0]} {props.carinfo[1]}!</h2>
  );
}

const carInfo = ["Ford", "Mustang"];

createRoot(document.getElementById('root')).render(
  <Car carinfo={carInfo} />
);

Pass Props from Component to Component

Attributes are also how you pass data from one component to another, as parameters.

Example

function Car(props) {
  return (
    <h2>I am a {props.brand}!</h2>
  );
}

function Garage() {
  return (
    <>
      <h1>Who lives in my garage?</h1>
      <Car brand="Ford" />
    </>
  );
}

createRoot(document.getElementById('root')).render(
  <Garage />
);

Note: React Props are read-only! You will get an error if you try to change their value.

Want to go beyond the notes?

Join CodingNow 2.0's React course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

React Props – FAQs

Quick answers about learning React Props in React.

This free note from CodingNow 2.0 explains React Props in React — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every React topic on CodingNow 2.0, including React Props, is 100% free with no signup required.
With focused practice, most students grasp React Props in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now