Skip to content

React Components and JSX for Beginners: Your First Component, JSX Rules and Curly Braces

NeedMyTools Academy

Sign in free to read the full lesson

Sign in or create a free account

Free forever. No card, no paywall.

React is a JavaScript library for building user interfaces out of small, reusable pieces called components. Instead of finding elements with querySelector and changing them by hand, as you did in the JavaScript course, you describe what the screen should look like for the current data, and React updates the page for you. A component is just a JavaScript function that returns markup written in JSX, a syntax that looks like HTML inside JavaScript. This lesson shows how a React page starts, the handful of rules that make JSX different from HTML, and how to put JavaScript values into your markup with curly braces. Every example runs the real React 19 in your browser.

Quick answer

A React component is a function whose name starts with a capital letter and which returns JSX, for example function Hello() { return <h1>Hello</h1>; }. You show it on the page by creating a root on an empty element and calling createRoot(...).render(<Hello />). JSX looks like HTML but follows JavaScript rules: return one parent element (or a fragment <>...</>), close every tag including <img />, write className instead of class and camelCase names such as onClick, and put any JavaScript expression inside curly braces, as in <p>{price} AED</p>.

30 min read and practice · Content checked on 19 November 2026

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.

Try it: Your first component on the page
Code
ResultUpdates as you type
Console
  1. 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
Sign in or create a free account

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.

Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.