Props are arguments provided to React components and are passed through HTML attributes.
Props is short for properties. |
React Props function like arguments in JavaScript and attributes in HTML. To pass props into a component, use the same syntax as HTML attributes.
Include a “brand” attribute in the Car element:
const |
The component receives the argument as a props object.
Utilize the brand attribute within the component.
function |
Props serve to transfer data between components, acting as parameters.
Pass the “brand” property from the Garage component to the Car component.
function |
If you’re sending a variable rather than a string, simply place the variable name inside curly brackets.
Define a variable called carName and pass it to the Car component.
function |
Or if it were an object:
Create an object called carInfo and pass it to the Car component.
function |
Note: React Props are immutable! Attempting to modify their value will result in an error. |