Components can be passed as props, short for properties. Props function like arguments in a function and are sent to the component as attributes. You will learn more about props in the next chapter.
Pass a color to the Car
component using an attribute, and utilize it within the render()
function.
function |
Components can be used within other components.
Embed the Car component within the Garage component.
function |
React emphasizes code reuse, so it’s advisable to split your components into separate files. To achieve this, create a new file with a .js
extension and place the component code inside it.
Ensure that the filename starts with an uppercase character. |
This is the new file, named “Car.js”.
function |
To use the Car
component, you need to import the file into your application.
Now that we’ve imported the “Car.js” file into the application, we can use the Car
component as if it were created directly in this file.
import |