Mark As Completed Discussion

Components and JSX

React is a component-based library, meaning that user interfaces are built using components. A component is a reusable piece of code that can be used to create user interfaces.

JSX is a syntax extension for JavaScript that allows you to write HTML-like syntax directly in your JavaScript code. It makes it easier to write and understand the structure of your components.

Here is an example of a React component using JSX:

SNIPPET
1import React from 'react';
2
3function Greeting() {
4  return (
5    <div>
6      <h1>Hello, World!</h1>
7      <p>Welcome to the world of React!</p>
8    </div>
9  );
10}
11
12export default Greeting;

In the example above, Greeting is a functional component that returns JSX code. The JSX code represents the structure of the component's UI. It contains HTML-like tags such as <div>, <h1>, and <p>.

By using the import statement and export default, the component can be imported and used in other parts of your application.

Components and JSX are fundamental concepts in React, and understanding them is crucial for building React applications.

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment