React Props

Props, short for properties, are arguments passed into React components. They are similar to function arguments in JavaScript and HTML attributes.

Tutorials dojo strip




Passing Props to Components

Props are passed to components using HTML-like attributes. In this example, the type attribute is passed to the Vehicle component.

JS




Receiving Props in Components

The component receives the prop as a props object. Here’s how to use the type attribute in the component:

JS




Passing Data Between Components

Props can also be used to pass data from one component to another. Here’s an example of passing a type property from the Garage component to the Vehicle component:

JS




Using Variables as Props

If you need to pass a variable instead of a string, use curly brackets. Here’s how to send a variable named vehicleType to the Vehicle component:

JS




Using Objects as Props

You can also pass an object as a prop. Here’s how to send an object named vehicleInfo to the Vehicle component:

JS

Tutorials dojo strip