Getting started with React
Tags: react, javascript, tutorial, beginners
Published: 2021-03-04 15:45:34

**React** is an open-source, front-end JavaScript library for building user interfaces or UI components. Released in May 2013, React is the most loved JavaScript framework because of its extra simplicity and flexibility.
![React is the most loved web framework](https://peerbits-wpengine.netdna-ssl.com/wp-content/uploads/2019/10/stack-overflow-statistic.jpg)

This tutorial will show you how to use React and build your first web application using it.

# What is JSX?
Before we begin, you must know what JSX is, as React uses it to function properly.

JSX (JavaScript XML) is a JavaScript syntax extension that makes it easier to write and add HTML. A simple example is shown below.
```jsx
var element = <h1>The quick brown fox jumps over the lazy dog</h1>;
```

React *doesn't require* JSX, but most people find it helpful as a visual aid when working with UI inside the JavaScript code. It also allows React to show more useful error and warning messages. We aren't going to use JSX in this tutorial.

# Setup
Because this tutorial is for beginners, we are going to start simple. We are only going to use two files:
* `index.html`
* `index.js` (or whatever you want it to be named)

## Setting up the HTML file
First, we are going to set up the HTML file. All we need to do is create a basic webpage, create a `<div>` element inside of the `<body>` element, and load the React library. We are going to use a CDN, so we don't have to download the full library.
```html
<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
```

The versions above are meant for ***development***, and not for production. Minified and optimized production versions of React are also available:
```html
<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
```

For this tutorial, we are going to use the development version.

The HTML file should look like this:
```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>My First React App</title>
  </head>
  <body>
    <div id="root"></div>
    <!-- Reference the React library here -->
    <script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
    <!-- Reference JS file here -->
    <script src="index.js"></script>
  </body>
</html>
```

## Setting up the JS file
Now we are going to set up the JavaScript file. The simplest React example looks like this:
```jsx
ReactDOM.render(
  <h1>Hello, world!</h1>,
  document.getElementById('root')
);
```

Here is the same example, but without JSX:
```javascript
ReactDOM.render(
  React.createElement('h1', null, 'Hello, world!'),
  document.getElementById('root')
);
```

Add the example **without JSX** to the JavaScript file. Make sure to save your work!

# Viewing the web app
Your website should look like this:
{% gist https://gist.github.com/mrwolferinc/b9f42ee1cb02f1f1c53e4c22b0d9afa2 %}

We can now view our newly created web app. Open `index.html` in a web browser, and you should see a heading that says "Hello, world!" on the page.
![What we should see](https://i.ibb.co/v4NDNMM/oie-g-OKw-BIs-Dy78o.png)

# Conclusion
Congratulations! You have just learned to create your very first web app using React! I hope you enjoyed this tutorial!