Master functional components in React. Learn how to define, export, and import code to build a professional, modular UI layout for your movie-browser app.
Previously in this course, we covered the essentials of Mastering JSX Syntax: Writing Declarative React Components. We moved beyond standard HTML to describe our UI as a tree of JavaScript functions.
Now, we’re going to take that knowledge and organize it. Instead of dumping all our code into a single file, we’ll learn to break our interface into reusable, maintainable functional components. This is the core of professional React development—building a clean, modular UI layout that scales as your project grows.
A functional component in React is just a plain JavaScript function that returns JSX. If you can write a function, you can write a React component.
Here is the mental model: A component is a blueprint for a piece of your user interface. When React renders, it calls your function, receives the JSX, and updates the DOM to match.
JSX// A simple functional component function Header() { return ( <header> <h1>Movie Browser</h1> </header> ); }
There are two strict rules for naming and defining components:
Header, not header). React treats lowercase tags as standard HTML elements and capitalized tags as custom components.<>...</>).To build our movie browser, we need a standard React structure. We'll separate our concerns by creating a components directory. This keeps our root App.jsx clean and readable.
Let’s create our first two components: Header and Footer.
Create a file named src/components/Header.jsx:
JSXexport default function Header() { return ( <header style={{ padding: CE9178">'1rem', background: CE9178">'#333', color: CE9178">'#fff' }}> <h1>My Movie Browser</h1> </header> ); }
Create a file named src/components/Footer.jsx:
JSXexport default function Footer() { return ( <footer style={{ marginTop: CE9178">'2rem', textAlign: CE9178">'center' }}> <p>© 2023 Movie Browser Inc.</p> </footer> ); }
In modern React, we use ES modules to share code. By using export default, we make the component available to be imported elsewhere.
Now, open your src/App.jsx file. We will import these components and assemble our basic UI layout:
JSXimport Header from CE9178">'./components/Header'; import Footer from CE9178">'./components/Footer'; function App() { return ( <div> <Header /> <main> <p>Welcome to my movie app!</p> </main> <Footer /> </div> ); } export default App;
By organizing our code this way, we've successfully transitioned from a single-file script to a component-based architecture. If you need to change the header later, you only touch Header.jsx.
To solidify this, let’s add a Sidebar component.
src/components/Sidebar.jsx.<nav> element with a list of links (e.g., "Home", "Popular", "Favorites").App.jsx, and place it inside the <main> container, next to your existing paragraph.export default, your App.jsx will throw an error saying the module cannot be found.header.jsx but you try to import Header, some build tools might complain, or you might run into issues when deploying to case-sensitive servers (like Linux). Always use PascalCase for component filenames.return (<div>...</div> <div>...</div>) is invalid. If you need two adjacent elements, wrap them in a single div or a Fragment: return (<><div>...</div><div>...</div></>).We've moved from writing basic JSX to architecting a real application. By defining functional components, we’ve created modular, reusable pieces of UI. We used export and import to manage our React structure, ensuring that our App.jsx remains a clean entry point for our layout. This modularity is the foundation of everything else we will build in this course, including Introduction to Component-Based Architecture in React.
Up next: We will bring these static components to life by learning how to apply styles and make them look professional.
Master the art of UI state management by adding a filter toggle to your movie app. Learn to control list rendering using boolean state and checkbox inputs.
Creating Static Components
Prop Drilling and Context API
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