Lesson 1 of 15
The UI Lego Blocks (Components & Props)
Lesson Updated: Apr 28, 2026
Requirement
Understand that a React application is just a collection of reusable custom HTML tags called "Components". You also need to learn how to pass data into these components using "Props" (short for properties) so that a single component can display different information.
Assignments (Start First)
- Simple beginner UI task: Create a functional component called
WelcomeBadge. It should return a simple<div>containing an<h1>that says "Welcome, User!" and a<p>tag with a short greeting. Render it on the screen. - Slightly improved version: Modify your
WelcomeBadgeto accept anameprop and aroleprop. Update the component so it dynamically says "Welcome, [name]!" and displays their role. Render three differentWelcomeBadgecomponents on the screen, passing different names and roles to each. - Practical real-world component: Build a
ProductCardcomponent. It should accept props forimageUrl,title,price, anddescription. Use standard CSS to style it like a real e-commerce card. Render a grid of four different products. - "The Escalation": Create a
NotificationBannercomponent. Pass it three props:message,type(which can be "success", "warning", or "error"), andisDismissible(a boolean). Use thetypeprop to change the background color of the banner. IfisDismissibleis true, render a small "X" button on the right side.
Lessons (Optional)
- Components: In React, components are just JavaScript functions that return JSX.
- JSX: It allows us to write HTML directly inside JavaScript. Wrap JavaScript variables in curly braces
{likeThis}. - Props: Props are arguments passed to your component functions. They are read-only.
- Rendering: You combine components by placing them inside one another, e.g.,
<ProductCard title="Shoes" />.
The Summary and Quizzes
- Concept explanation: Components let you split the UI into independent, reusable pieces. Props let you pass data into those pieces to make them dynamic.
- Why it works in React: React uses these components to build a "Virtual DOM". When props change, React intelligently figures out exactly which parts of the screen need to be updated.
- Challenge question: If you have a
UserProfilecomponent that receives auserobject as a prop, and you want to display the user's email inside an<h2>tag, what is the exact JSX syntax you would write inside the component?