# Functional Components

> The modern standard for building React UIs using plain JavaScript functions.

Subject: React | Lesson 6 of 48 | 3 min read
Interactive lesson: https://codewithanimation.in/react/functional-components
Previous: [One-Way Data Flow](https://codewithanimation.in/react/one-way-data-flow.md) | Next: [Props & Destructuring](https://codewithanimation.in/react/props-and-destructuring.md)

## What they are

A **Functional Component** is simply a JavaScript function that returns a React Element (usually written as JSX).

In modern React, this is the default and recommended way to build components, entirely replacing the older Class-based syntax.

## Why it matters

Functions are vastly simpler than classes. You don't have to worry about confusing `this` binding rules, constructor functions, or complex lifecycle methods (`componentDidMount`, etc.).

Coupled with React Hooks (which we'll learn later), Functional Components can do everything classes could do, but with significantly less boilerplate and better code reuse.

## How it works

When React encounters a custom tag like `<Profile />`, it calls your `Profile()` function.

Your function executes, calculates any necessary logic, and returns a JSX tree. React then takes that tree and renders it to the screen.

## Common mistake: The capitalization trap

If you name your function `profile()` (lowercase 'p') and try to render it as `<profile />`, React will assume it's a built-in HTML tag (like `<div>` or `<span>`).

Because `<profile>` doesn't exist in HTML, nothing renders correctly. You **must** capitalize custom React components: `function Profile()`.

## Tip: UI = f(state)

The best way to think about a Functional Component is as a pure math function. The UI is just the output of a function `f` given a specific `state`. If the state changes, the function runs again and produces new UI.

## Try it: Your First Component

Here is a standard Functional Component. Notice how it's just a regular JavaScript function returning JSX markup.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/react/functional-components

## Check yourself

### Question 1

What is a Functional Component in React?

- A. A JavaScript function that returns React Elements.
- B. A class that extends `React.Component`.
- C. A function that mutates the browser's DOM directly.

Correct answer: A

A functional component is just a plain JavaScript function that returns JSX.

- Why not B: That describes the older Class Component syntax.
- Why not C: React components return Virtual DOM elements; React handles the real DOM mutations.

### Question 2

Why must Functional Components start with a capital letter?

- A. To distinguish them from standard HTML elements in JSX.
- B. Because JavaScript functions require capital letters.
- C. To make the component compatible with React Hooks.

Correct answer: A

JSX compilers treat lowercase tags as built-in DOM elements (like `div`) and capitalized tags as custom React components.

- Why not B: JavaScript doesn't care, but the JSX compiler does.
- Why not C: Hooks rely on the call order, not the capitalization. Capitalization is strictly for JSX compilation.

### Question 3

Why did React move away from Class components to Functional components?

- A. Because Functional components don't require `this` binding and are simpler to write.
- B. Because Class components are no longer supported in modern browsers.
- C. Because Functional components render 10x faster.

Correct answer: A

Classes required complex boilerplate and confusing `this` context rules. Functions + Hooks provided a much cleaner mental model.

- Why not B: JavaScript classes are fully supported in all modern browsers.
- Why not C: The performance difference is negligible. The shift was about developer experience and code reuse.

## Remember this

- A Functional Component is a JavaScript function that returns JSX.
- Always start component names with a Capital letter.
- Functional components are the modern standard; avoid using Class components for new code.
