# Elements vs. Components

> A Component is the factory. An Element is the product it builds.

Subject: React | Lesson 3 of 48 | 3 min read
Interactive lesson: https://codewithanimation.in/react/elements-vs-components
Previous: [JSX & Compilation](https://codewithanimation.in/react/jsx-and-compilation.md) | Next: [Virtual DOM & Reconciliation](https://codewithanimation.in/react/virtual-dom-reconciliation.md)

## What they are

An **Element** is a plain JavaScript object describing what you want to see on the screen. It is lightweight, immutable, and has no methods. It looks like this under the hood: `{ type: 'button', props: { className: 'blue' } }`.

A **Component** is a function (or class) that optionally accepts inputs (props) and returns a React Element. It is the blueprint or factory that produces Elements.

## Why it matters

Confusing the two leads to fundamentally broken React applications. When you write `<MyButton />` in JSX, you are creating an *Element* that tells React to execute the `MyButton` *Component* later.

If you treat a Component like a regular function and call it directly (e.g., `MyButton()`), you bypass React's lifecycle and hook system entirely. React won't know the component exists.

## How they interact

When React renders your app, it calls your Components to ask them what they want to display. Your Components return a tree of Elements.

React then takes that tree of Elements, compares it to the previous tree (reconciliation), and updates the real DOM to match.

## Common mistake: The function call trap

Never call a component as a direct function: `const ui = Header()`. While it might seem to work initially because it returns JSX, it breaks all React hooks (`useState`, `useEffect`) because React hasn't officially mounted the component in its internal tree. Always use JSX: `<Header />`.

## Tip: Uppercase vs Lowercase

React distinguishes between DOM elements and your custom components by casing. Lowercase tags (`<button>`) create DOM elements. Uppercase tags (`<Button />`) tell React to run your Component function.

## Try it: The Factory and the Product

Watch how a single Component (the factory) produces multiple distinct Elements (the products) to form the UI tree.

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

## Check yourself

### Question 1

What is a React Element?

- A. A function that returns UI logic.
- B. A plain JavaScript object describing what to render.
- C. A physical DOM node in the browser.

Correct answer: B

An Element is simply an immutable JavaScript object that tells React what should appear on the screen.

- Why not A: That is the definition of a Component, not an Element.
- Why not C: Elements are abstract JavaScript descriptions, not real DOM nodes.

### Question 2

Why shouldn't you call a Component like a standard function (e.g. `const ui = MyComponent()`)?

- A. It causes a strict syntax error in Babel.
- B. It bypasses React's internal component tree, breaking hooks like `useState`.
- C. It makes the function run synchronously instead of asynchronously.

Correct answer: B

When you use `<MyComponent />`, React officially registers it in its internal tree, enabling state and effects. Calling it directly skips this registration.

- Why not A: Babel won't stop you; it's valid JavaScript. But it breaks React's runtime.
- Why not C: React renders are generally synchronous anyway. The issue is missing the mount lifecycle.

### Question 3

How does React know whether `<Foo />` is a DOM node or a custom Component?

- A. By checking if it starts with a capital letter.
- B. By looking for a `render()` method inside it.
- C. By checking if it's imported at the top of the file.

Correct answer: A

JSX compilers treat lowercase tags as strings (built-in DOM elements) and uppercase tags as variable references (custom Components).

- Why not B: React relies entirely on the capital letter convention for JSX compilation.
- Why not C: React doesn't parse your imports, it only looks at the JSX tag casing.

## Remember this

- A Component is a function. An Element is the object it returns.
- Never call components directly as functions (`MyComponent()`); always use JSX (`<MyComponent />`).
- Capitalize custom Components; use lowercase for standard DOM elements.
