React uses JSX (JavaScript XML) to write UI components. It's a syntax extension that allows you to write HTML-like structures within your JavaScript code. However, JSX is not actual HTML; it's transformed into JavaScript function calls at build time.

JSX Basics

JSX looks familiar to HTML but offers more power:

Here's an example of a simple JSX element:

const element = <h1>Hello, world!</h1>;

React Components

React components are reusable building blocks for your UI. Each component is a JavaScript function that returns JSX describing the UI it renders.

Here are key aspects of React components:

Here's an example of a simple React component:

function Greeting(props) {
  return (
    <div>
      <h1>Hello, {props.name}!</h1>
    </div>
  );
}

This component takes a name prop and displays a greeting message with the provided name.

Advantages of JSX and Components

Beyond the Basics

JSX and components offer a powerful foundation for building complex UIs in React. Here are some additional concepts to explore:

By mastering JSX and components, you'll be well-equipped to build dynamic and interactive user interfaces with React.