Functional Components and Declarative UI0%

Functional Components and Declarative UI

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

Functional Components and Declarative UI

1. What is a React Component?

In modern React, a component is a JavaScript function that accepts arbitrary inputs (called props) and returns a React element (written in JSX) describing how a section of the user interface should appear.

Components allow you to split the UI into independent, reusable pieces, and think about each piece in isolation.

JSX
// A clean, modern functional component
export default function CourseBadge({ title, duration }) {
return (
<div className="course-badge">
<span className="badge-title">{title}</span>
<span className="badge-time">{duration}</span>
</div>
);
}

2. Capitalization Convention

In React, component names must always start with an uppercase letter (e.g., CourseCard, Header, UserProfile).

  • If an element starts with a lowercase letter (e.g., <div>, <span>, <button>), React treats it as a built-in standard HTML tag.
  • If an element starts with an uppercase letter (e.g., <CourseCard />), React recognizes it as a custom component and executes the corresponding JavaScript function.
JSX
// ❌ Treated as an unknown HTML tag; will not invoke the function
function button() {
return <button className="custom-btn">Click me</button>;
}
// Using <button /> invokes the standard HTML button, not your function
 
// ✅ Treated as a custom React component
function CustomButton() {
return <button className="custom-btn">Click me</button>;
}
// Using <CustomButton /> invokes your custom function

3. Pure Functions and the Declarative Contract

React components are modeled after pure functions in computer science:

  • Same Inputs -> Same Output: Given the same props and state, a component should always return the exact same JSX.
  • No Side Effects During Render: A component function should simply describe what the UI should look like. It must not mutate external variables, modify the DOM directly, or start network requests inside the component body during rendering.
JSX
// ❌ Impure Component: Mutates an external variable during rendering!
let guestCount = 0;
 
export function Cup() {
guestCount = guestCount + 1; // Side effect during render!
return <h2>Tea cup for guest #{guestCount}</h2>;
}
 
// ✅ Pure Component: Operates strictly on inputs (props)
export function Cup({ guestNumber }) {
return <h2>Tea cup for guest #{guestNumber}</h2>;
}

4. Class Components vs Modern Functional Components

Prior to React 16.8, complex components with state and lifecycle methods had to be written as ES6 Classes inheriting from React.Component:

JSX
// Legacy Class Component (Older Codebases)
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}

Today, the entire React ecosystem has standardized on Functional Components with React Hooks:

  • Simpler Code: No this binding headaches, constructor methods, or class boilerplate.
  • Smaller Bundle Sizes: Functions minify and compress far better than JavaScript ES6 classes.
  • Code Sharing via Custom Hooks: Business and state logic can be extracted into reusable custom hooks without convoluted Higher-Order Component (HOC) or Render Prop patterns.

Interactive Quiz

Practice Quiz

Question 1
What rule must the naming of a React functional component strictly follow?
Question 2
What is the primary characteristic of a pure React component?
Question 3
What version of React introduced Hooks, transitioning the ecosystem from Class components to Functional components?
Question 4
Why are modern functional components preferred over legacy class components?
Question 5
What does a functional component return?
Next Lesson

Component Props and Read-Only Data Flow

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext