Learn to build a reusable MovieCard component to display dynamic data. Master props and component architecture for a scalable React movie browser app.
Previously in this course, we covered Passing Data with Props: A Guide to React Component Communication. Now that you understand the basic mechanics of sending information from a parent to a child, it’s time to apply that knowledge to our project.
In this lesson, we are moving beyond static placeholders. We will build a single, highly reusable component—the MovieCard—and learn how to inject unique data into multiple instances of that card to create a professional movie browser interface.
When building UI, repeating code is the enemy of maintainability. If you need to update the layout of your movie cards later, you don't want to hunt down five different div blocks in your App.jsx.
A reusable component acts as a template. By using props, we define the structure once and pass the content dynamically. This is the cornerstone of declarative UI development.
In our current project, we likely have a hardcoded list of movies. Let’s refactor that into a clean, reusable MovieCard component.
First, create a new file named MovieCard.jsx. We will design it to accept title and description as props:
JSX// MovieCard.jsx export default function MovieCard({ title, description }) { return ( <div className="movie-card"> <h3>{title}</h3> <p>{description}</p> </div> ); }
Now, back in your App.jsx, import this component and use it multiple times. Notice how we pass unique data to each instance:
JSX// App.jsx import MovieCard from CE9178">'./MovieCard'; function App() { return ( <div className="app-container"> <h1>Movie Browser</h1> <MovieCard title="Inception" description="A thief who steals corporate secrets through dream-sharing technology." /> <MovieCard title="Interstellar" description="A team of explorers travel through a wormhole in space." /> </div> ); }
By passing different strings to the title and description attributes, we’ve created a dynamic interface without duplicating the underlying HTML structure.
You might notice that as your app grows, you often pass data from a parent (like App.jsx) to a child (MovieCard). This is the foundation of prop drilling.
Prop drilling refers to the process of passing data down through the component tree. While it can become cumbersome in massive applications, it is the fundamental way React components share information. For now, focus on keeping your data flow clean: the parent manages the data, and the child (the MovieCard) simply renders it.
Your goal is to expand the MovieCard to include a year prop.
MovieCard.jsx to accept a third prop named year.<span> or <small> tag inside the component to display the year.App.jsx to include a year attribute (e.g., year="2010").undefined. Always provide default values or ensure your data source is robust.MovieCard starts doing too much—like fetching its own data or managing complex state—it’s time to break it down further, perhaps into a MovieTitle or MovieDescription sub-component.import statement in the parent file. Always check your console for "Component is not defined" errors.We've successfully moved from static code to dynamic UI. By extracting our movie display logic into a reusable component, we've made our code easier to read and maintain. We've also practiced the fundamentals of passing props to customize these instances. This component-based approach is how we build everything from simple websites to complex applications, as we discussed in our Introduction to Component-Based Architecture in React.
Up next: We will explore Component Composition, where we learn how to nest components within each other to build even more complex and flexible UI structures.
Learn how to initialize a professional React project using Vite. We’ll cover the project directory structure and how to launch your fast development environment.
Dynamic Movie Cards
Polishing the UI
Finalizing the Movie Browser
Review of Component Lifecycle
Review of State Management
Building a Modal Component
Introduction to PropTypes
Performance Optimization Basics
Handling Browser History
Working with LocalStorage
Building a Favorites List
Handling Media in React
Introduction to Testing
Debugging React Apps
Deployment Basics
Using External Libraries
Advanced