LearnThatStack Ace your next interview
React · question
Question 3 of 103

What's the difference between React elements and React components?

beginner
← All React questions
Re-explain

A React element is a plain object describing what should appear on screen, while a React component is a function or class that returns elements. Elements are the smallest building blocks of a React app, and components are the reusable pieces that produce them.

const element = <h1>Hello, World!</h1>;

JSX like this creates an element. React never changes an element after it's created, so to show something different, React calls your components again and gets new elements.

// Function component
function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}

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

A component accepts inputs called props and can be reused anywhere. You write <Welcome name="Sara" /> to use it, and React calls Welcome with those props to get the element to render.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for React One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • Once your component returns new elements, how does React work out what to change in the real DOM? A strong answer names reconciliation. React diffs the new element tree against the last one and touches only the DOM nodes that changed.
  • What does JSX like <Welcome name='Sara' /> compile to, and what does the resulting element hold? It compiles to a React.createElement or jsx call that returns a plain object. Its type is the Welcome function itself, and props holds name.
  • Why does React care whether a JSX tag starts with a capital letter? Lowercase tags become strings like 'h1' for DOM elements. Capitalized tags become a reference to your component, which React then calls.
  • What goes wrong if you call Welcome(props) as a plain function instead of rendering <Welcome />? React never sees a component, so it gets no node of its own. Its hooks belong to the parent, and a conditional call breaks hook order.
  • Would you write a function or a class component today, and is there still a case for classes? Function components with Hooks are the default. Error boundaries are the usual exception, since they still rely on class methods like componentDidCatch.

What you can say

  1. A React element is a plain object that describes what should be on screen. A component is a function or class that returns elements.
  2. Writing JSX like an h1 that says Hello World creates an element, and elements are the smallest building blocks of the app.
  3. A component is the reusable piece. It's either a function that returns JSX or a class whose render method does.
  4. It takes inputs called props, so when I write Welcome with name Sara, React calls Welcome with those props and gets back the element to render.
  5. Elements are fixed once created, so React can't edit one in place. To show anything different, it calls my components again and gets new elements.

Weak answers to avoid

  • Treats elements and components as synonyms They are different things. An element is a plain object describing UI, and a component is a function or class that returns elements. Say both halves.
  • Says an element is a DOM node An element is a lightweight JavaScript object, not a real DOM node. React creates or updates DOM nodes later from these descriptions.
  • Claims React mutates elements to update the UI React never changes an element once it's made. It calls the component again with new props or state and gets new elements back.
  • Only recites class vs function syntax Two ways to write a component doesn't answer the question. Explain that a component returns elements and React calls it with props.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the React cheatsheet.

← Back to all React questions
Pro · $10/mo

88 of 103 React answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime