Skip to content
Parwaz DigitalMarketing · Web · Courses

Web Development Course · Module 5, lesson 2

Passing data with props and rendering lists

Make components reusable by passing data through props, and render lists of items from arrays with map and stable keys.

What you will learn

  • Pass data into components using props
  • Render a list of components from an array with map
  • Give list items stable, unique keys

Props are how a parent component passes data to a child, much like attributes on an HTML element. <ProductCard name="Croissant" price={250} /> passes two props. The component receives them as one object, and destructuring keeps it readable: function ProductCard({ name, price }) { ... }. Props flow in one direction, from parent to child, and a component should treat them as read-only.

The children prop holds whatever you put between a component's opening and closing tags. This is useful for wrapper components such as a Card or Section that add layout and styling around any content. With TypeScript, you can describe the shape of props in a type, so your editor warns you when a prop is missing or has the wrong kind of value.

To render a list, use the array method map inside JSX: {products.map((product) => <ProductCard key={product.id} {...product} />)}. Each item needs a key prop that is unique among its siblings and stays the same between renders, usually an ID from the data. React uses keys to track which items changed. Avoid using the array index as the key if items can be reordered or removed.

Practice task

Move your products into an array of objects with id, name and price, then render a ProductCard for each with map, passing the data as props and using the id as the key.

Web Development Course

Learn this properly,with a final project.

These pages summarise each lesson. The full course teaches them hands-on. Message us for the current fee, schedule, and format.

Available for new projects — Replies within one business day