DevPath · Learn to code ESPTEN

Components, JSX and state

What is React? Components and JSX

React: interfaces with components

React is a library for building interfaces. The core idea: the UI is split into reusable components. In modern React, a component is simply a function that returns what should be painted.

function Welcome() {
  return <h1>Hello, React!</h1>;
}

JSX

JSX lets you write markup inside JS. Between curly braces { } you can embed JavaScript expressions:

function Greeting() {
  const name = "Ann";
  return <h1>Hello, {name}</h1>;
}

Key JSX rules:

function Card() {
  return (
    <div className="card">
      <h2>Title</h2>
      <p>Content</p>
    </div>
  );
}

In these exercises you write the component and see it rendered in the preview instantly.

Put this into practice

DevPath is a hands-on course: you read the theory here; in the app you put it into practice with exercises that really run, offline.

Start free in the app →
Props: passing data to a component →