From the course: Master React 19 and Next.js 16 with Hands-On Projects and Real-World Applications

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Working with props in React components

Working with props in React components

In this session, you are going to learn how to pass data, or props, between React components. Let's start with an empty div. Ok, let's introduce our first component. I've added a blue component that uses inline styles to set its text color to blue. Now I am integrating the blue component into our app component. Now I've added a new component, red component, styled with inline styles to display red text. This will later be refactored for better maintainability. Let's add the red component to our app. Now you can see both colored components. I am creating a third green component to further demonstrate the concept. Let's add it to our main application, completing the set of colored components. As you can see, these three components have a similar structure. The only difference between them is the color value. Now it is time to create a reusable component, which will improve our code and avoid repetition. I've introduced ColorfulComponent, which accepts a props object. The text color can…

Contents