A first component and the render model
Content revised on 3 October 2026. Any completion marker earned before this revision refers to the earlier content version and does not confirm completion of this revised lesson.
Learning goals
- Explain component, render and commit at an introductory level.
- Read and test a semantic function component.
Assumptions and scope
- Browser-only learning project; no server rendering or routing.
- First three lessons can be read before setup; all executable files are supplied.
Content revised on 3 October 2026. Any completion marker earned before this revision refers to the earlier content version and does not confirm completion of this revised lesson.
React helps you describe a user interface as a collection of components. In this course, a component is a JavaScript function that returns a description of what should appear. Start with an ordinary page question: what information should a learner see at a study desk? A heading and a short instruction are enough for a first component. You do not need a server, account system or complex design to understand the model.
The returned description uses JSX, a syntax that resembles HTML inside JavaScript. A build tool transforms JSX before the browser runs it. The browser does not natively execute a file containing arbitrary JSX. Our supplied project already connects an HTML entry page, a JavaScript entry module and the main component. The setup lesson explains how to run it. For these first lessons, you can inspect the source and predict the output before installing anything.
Rendering means React calls components to calculate their descriptions. Committing means applying the necessary changes to the browser's document. Those are related stages, not a promise that every component call changes every visible element. When the relevant inputs stay the same, a component should describe the same output. Keep rendering free of actions such as sending a request, changing a shared array or incrementing an outside counter.
Use a capitalized name for your own component so JSX can distinguish it from a built-in HTML element. Define small components at module level and use them through JSX. A component's name is an organizing tool for developers; the user still encounters headings, paragraphs, buttons and other browser elements. Choosing those semantic elements carefully makes the result easier to understand and operate with assistive technology.
A useful first debugging method follows the path from file to screen. Check that the component is exported, imported using the correct form, and actually included in the parent output. Then check the returned JSX for a matching enclosing element and valid tag closure. Finally inspect the browser console for the first relevant error. A blank screen rarely justifies replacing the entire project; a small broken connection may be responsible.
Treat the component as a unit you can explain and test. Predict its heading, render it, and compare the observation with the prediction. Change one piece of text and repeat. Our first automated check looks for a heading by its role and accessible name, rather than checking a generated internal object. This habit connects code to user-visible behavior. Later lessons add data and interactions, but the same question remains: given these inputs, what should the interface show, and what evidence would tell us it is wrong?
Official concept references (verified 3 October 2026): [React: first component](https://react.dev/learn/your-first-component) and [pure components](https://react.dev/learn/keeping-components-pure). Original example and exercises.
Worked example: A small study-desk component
Read FirstComponent in app/src/examples.jsx. Predict its visible content, then open the lesson examples in the running app after the setup lesson.
Solution
export function FirstComponent() {
return <section><h2>Study desk</h2><p>One small step at a time.</p></section>;
}
Expected observation: a level-two heading “Study desk” and paragraph “One small step at a time.” This is a pure description: it does not save data or modify a shared object. The foundation test finds the heading by role and level, then checks the paragraph.
Read each row as a labeled relationship; no color or position is needed to understand it. All project data are fictional learning examples.
| Layer | Responsibility | Course file |
|---|---|---|
| HTML entry | Contains the root element | app/index.html |
| Entry module | Creates the React root | src/main.jsx |
| Component | Describes user-visible content | src/examples.jsx |
Independent practice
-
Write a component named BreakNote that returns a paragraph reading “Pause and stretch.”
-
A file exports default function Welcome(). Another file writes import { Welcome } from "./Welcome.jsx". What must change?
-
A component increments a module-level visits variable during rendering to count page visits. Explain the bug and the appropriate next step.
Practice answers and reasoning
-
function BreakNote() { return <p>Pause and stretch.</p>; }
The function is capitalized and returns semantic JSX. It is defined outside other components; use <BreakNote /> where needed.
-
Use import Welcome from "./Welcome.jsx"; or deliberately change the export to a named export and keep both sides consistent.
Braces request a named export. The supplied default export must be imported without braces.
-
Rendering should not increment shared data. Remove the mutation; first define whether a “visit” means a user action, navigation or an external analytics event.
React may render again for reasons other than a new visit. Counting function calls is not a reliable user-event definition.
Common errors to avoid
- Using a lowercase name for a custom JSX component.
- Treating a render call as a once-only event.
Exit check
-
Does JSX reach the browser unchanged in this project?
-
Does one render necessarily replace the whole page?
Exit-check answers
-
No.
Vite transforms the source and serves browser-executable modules.
-
No.
React calculates an output and commits the necessary changes.