React Props
React Props
React Props
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
React Props
❮ Previous Next ❯
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
Add a "brand" attribute to the Car element:
https://www.w3schools.com/REACT/react_props.asp 1/9
4/2/25, 10:39 a.m. React Props
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Example
Use the brand attribute in the component:
function Car(props) {
return <h2>I am a { props.brand }!</h2>;
}
Run Example »
Get Certified!
school
w3 s
5
CE
02
TI 2
Complete the React modules, do the exercises, take the exam and become
R
FI .
ED
w3schools certified!!
$95 ENROLL
Pass Data
Props are also how you pass data from one component to another, as parameters.
Example
Send the "brand" property from the Garage component to the Car component:
function Car(props) {
return <h2>I am a { props.brand }!</h2>;
}
https://www.w3schools.com/REACT/react_props.asp 2/9
4/2/25, 10:39 a.m. React Props
function Garage() {
Tutorials
return ( Exercises Services Sign Up Log in
<>
HTML
CSS JAVASCRIPT
<h1>Who lives in my SQL PYTHON
garage?</h1> JAVA PHP HOW TO W3.CSS C
<Car brand="Ford" />
</>
);
}
Run Example »
If you have a variable to send, and not a string as in the example above, you just put
the variable name inside curly brackets:
Example
Create a variable named carName and send it to the Car component:
function Car(props) {
return <h2>I am a { props.brand }!</h2>;
}
function Garage() {
const carName = "Ford";
return (
<>
<h1>Who lives in my garage?</h1>
<Car brand={ carName } />
</>
);
}
https://www.w3schools.com/REACT/react_props.asp 3/9
4/2/25, 10:39 a.m. React Props
Run Example »
Tutorials Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Or if it was an object:
Example
Create an object named carInfo and send it to the Car component:
function Car(props) {
return <h2>I am a { props.brand.model }!</h2>;
}
function Garage() {
const carInfo = { name: "Ford", model: "Mustang" };
return (
<>
<h1>Who lives in my garage?</h1>
<Car brand={ carInfo } />
</>
);
}
Run Example »
Note: React Props are read-only! You will get an error if you try to change their value.
?
Exercise
https://www.w3schools.com/REACT/react_props.asp 4/9
4/2/25, 10:39 a.m. React Props
Which one is a correct way of sending the value 'John' via the 'firstname'
Tutorials Exercises Services
property to the Person component?
Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
root.render(<Person firstname='John' />);
root.render(Person(firstname='John'));
Submit Answer »
❮ Previous Next ❯
ADVERTISEMENT
https://www.w3schools.com/REACT/react_props.asp 5/9
4/2/25, 10:39 a.m. React Props
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
https://www.w3schools.com/REACT/react_props.asp 6/9
4/2/25, 10:39 a.m. React Props
COLOR PICKER
Tutorials Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
ADVERTISEMENT
ADVERTISEMENT
https://www.w3schools.com/REACT/react_props.asp 7/9
4/2/25, 10:39 a.m. React Props
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
ADVERTISEMENT
Java Tutorial
Tutorials
C++ Tutorial
Exercises Services Java Reference
Angular Reference
Sign Up Log in
jQuery Tutorial jQuery Reference
HTML
CSS TopJAVASCRIPT
Examples SQL PYTHON JAVA
Get PHP
Certified HOW TO W3.CSS C
https://www.w3schools.com/REACT/react_props.asp 9/9