Component Component Basics

Last updated: 2026-11-02

Component Component Basics

A component is the smallest reusable unit of a React application: a function that receives props and returns JSX. Once you split an interface into components, each part can be developed, tested and reused on its own, and a complete page is assembled from those pieces like building blocks. Because every component is a plain function, there is no class syntax to learn before you start.

GroupCore Concepts
KindPattern
SinceEarliest React versions

ℹ️ Info The editor transpiles JSX to JavaScript and renders the real UI in a sandbox; components mount automatically — no manual render call needed.

📝 Syntax

function Welcome({ name }) {   // A component = a function returning JSX; the name must be capitalized
  return <h1>Hello, {name}</h1>
}

<Welcome name="Alice" />        // Used just like an HTML tag

⚙️ Parameters

propsThe data object passed in by the parent; components usually destructure it directly and must treat it as read-only.

Returns:A component function returns a piece of JSX (or null) describing what that component should render.

▶ Example

The example runs out of the box: it auto-renders when expanded, and edits take effect instantly.

Output:

Under the heading "Component reuse demo" three greetings appear — Hello, Alice!, Hello, Bob! and Hello, React Learner! — the same component rendered three times with different props.

💡 Key Points

⚠️ Warning Component names must start with a capital letter: a lowercase tag is treated by React as a plain HTML element.
💡 Tip Do not define a component inside another component — every render creates a new component type and rebuilds the whole subtree, so move it out to the outer scope.
ℹ️ Info Modern React only uses function components; class components survive in older code and the two styles can coexist.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q Why must React component names start with a capital letter?
A The JSX compiler decides by the first letter: <div> compiles to a string tag while <Welcome> compiles to a component reference, so a lowercase name is treated as a native HTML element.
Q Can one file hold several components?
A Yes — keeping a few small, related components in one file is common. The convention is one main component per file, with small helpers kept alongside it.
Q What is the difference between function and class components?
A Class components use class syntax and lifecycle methods, while function components use Hooks for state and effects. Function components are the recommended choice for new projects.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏