Question presented to candidate: "You keep hearing both words. What is the actual difference between a React element and a React component?"
What a strong answer should cover:
- A component is a function (or class) that accepts props and returns a description of UI. It is a blueprint.
- An element is the plain object that description actually is — a single instruction, produced by calling the component in JSX.
- An element is not a DOM node and not a component instance; it is data.
- The object shape:
$$typeof,type,key,props.typeis the function itself for a custom component, or a string like"h1"for a host element. - Elements are frozen and created fresh on every render — which is precisely why they are cheap and why diffing is just object comparison.
<Greeting />is sugar forcreateElement(Greeting, ...); JSX produces elements, it does not call the component.- Signal of depth: React calls the component; you never do. That is why calling
Greeting()directly breaks Hooks.
Clarifying questions expected:
- "Do you want me to include what
$$typeofis for?" (XSS protection for JSON-injected elements.)
Code / implementation expected: Optional, but showing createElement output next to JSX makes the point instantly.