In this lesson you will
- Explain what React does differently from changing the DOM by hand
- Write a component and render it into the page with createRoot
- Follow the JSX rules: one parent, closed tags, className and camelCase
- Put values and expressions into JSX with curly braces
What React is and how a React page starts
In plain JavaScript you keep the page in sync with your data yourself: when the cart changes, you find the counter element and set its text, then find the total and set that too. Miss one place and the page shows old data. React turns this around. You write components that say "given this data, the screen looks like this", and when the data changes React works out which parts of the page changed and updates only those. Meta released React in 2013; it is free and open source, and it is the most widely used library for this job.
A React page needs one empty element for React to take over, usually <div id="root"></div>. Your script imports createRoot from react-dom/client, creates a root on that element and calls render with the component to show. From then on React owns everything inside the root: do not change it with innerHTML or append yourself. In the examples here the script has type="text/jsx", so the playground turns your JSX into JavaScript before it runs. In a real project a build tool such as Vite does the same job.
Console
- Console messages, errors, form data and clicked links appear here.
The page starts with an empty div. React fills it with whatever Welcome returns. Change the text inside <h1> and the result updates as you type. Rename the function to welcome with a small w, and also in <welcome />, and nothing useful appears: React treats lowercase names as HTML tags.
Sign in free to read the full lesson
You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.
Unlocks after sign-in:
- 3 more sections with live code examples
- Common mistakes to avoid
- Hands-on coding exercise with automatic checks
- Practice quiz and the graded lesson test
Free forever. No card, no paywall.
Questions people ask
Is React a framework or a library?
React calls itself a library for web and native user interfaces. It handles components and updating the screen; routing, data loading and building are left to tools around it. Frameworks such as Next.js are built on React and add those parts.
Can browsers run JSX directly?
No. JSX must be compiled to JavaScript first. Build tools such as Vite, or frameworks such as Next.js, do it when you save a file. This playground does it in your browser just before the example runs.
Do I have to use JSX to write React?
No, you can call createElement yourself, but almost every project and tutorial uses JSX because it is far easier to read. Learn JSX; it is what you will see at work.
How do I start a new React project on my computer?
Install Node.js, then use a framework such as Next.js, or Vite for a plain React app, with npm create vite@latest and the React template. The React documentation lists the current recommended options on its "Creating a React App" page.
Why does React need a div with the id root?
createRoot needs one existing DOM element to manage. The id root is only a convention; any empty element works. Everything React draws goes inside it, and the rest of the page stays as it is.
Sources
Facts in this lesson were checked against these official pages on 19 November 2026.
- React docs: Your First Component
- React docs: Writing Markup with JSX
- React docs: JavaScript in JSX with Curly Braces
- React reference: createRoot
- React docs: Creating a React App
Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.