AI Hints
Home›React Tutorial›Getting Started
React · Lesson 3 of 120

Your First Component

A function that returns UI.

⏱ 2 min read▶ Video at 1:42🎓 Free
Watch this lesson in the React courseWatch on YouTube ↗Full React course

A React component is just a JavaScript function. Its name starts with a capital letter, and it returns what should appear on the page.

  • A function
  • Capital letter
  • Returns the UI

Hello, React

App is a function that returns a heading and a paragraph. Export default lets React find it. Run it. The browser shows exactly what the function returned.

App.jsxjsx
export default function App() {
  return (
    <div>
      <h1>Northwind Bikes</h1>
      <p>Welcome to our shop!</p>
    </div>
  );
}
Also uses style.css
body{font-family:-apple-system,Helvetica,Arial,sans-serif;margin:22px;font-size:21px;color:#1d1d1f;background:#fafafa}
h1{font-size:34px;margin:0 0 14px} h2{font-size:26px;margin:0 0 10px}
button{font-size:19px;padding:9px 18px;border-radius:9px;border:0;background:#61dafb;color:#111;font-weight:600;margin:4px 6px 4px 0}
input{font-size:19px;padding:8px 10px;border:2px solid #bbb;border-radius:8px}
li{margin:5px 0} .box{padding:14px;border-radius:12px;background:#fff;border:2px solid #ddd;margin:8px 0}
.done{text-decoration:line-through;color:#999} small{color:crimson;display:block;font-size:16px} .big{font-size:64px;font-weight:800}

Setting up

To build React apps on your computer, install Node, then create a project with Vite. NPM create vite gives you a ready made React app, with a fast development server.

keyvalue
InstallNode.js
Createnpm create vite@latest
Runnpm run dev
EditorVS Code

Summary

A component is a capitalised function that returns UI. Next, JSX.

Key takeaways
  • function App()
  • return (...)
  • export default
Next up: JSX — HTML in JavaScript