Getting started with React

Create a project, and understand components and JSX.

React builds a page from components: functions that return what should appear. When data changes, React updates only what needs to change. Know HTML, CSS and JavaScript first.

HTML
npm create vite@latest my-app -- --template react
cd my-app
npm install
npm run dev
React (JSX)
export default function Welcome() {
  const city = "Erode";
  return (
    <section className="card">
      <h1>Vanakkam, {city}!</h1>
      <p>2 + 3 = {2 + 3}</p>
    </section>
  );
}
  • Curly braces put a JavaScript value into JSX.
  • Use className, because class is a JavaScript keyword.
  • Component names start with a capital letter.
  • A component returns one parent element.
Props and lists โ†’