What is React (2024)

What is React (1)

React is a JavaScript library created by Facebook

React is a User Interface (UI) library

React is a tool for building UI components

React Quickstart Tutorial

This is a quickstart tutorial.

Before you start, you should have a basic understanding of:

For a full tutorial:

Go to our React Tutorial ❯

Adding React to an HTML Page

This quickstart tutorial will add React to a page like this:

Example

<!DOCTYPE html>
<html lang="en">
<title>Test React</title>

<!-- Load React API -->
<script src= "https://unpkg.com/react@16/umd/react.production.min.js"></script>
<!-- Load React DOM-->
<script src= "https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<!-- Load Babel Compiler -->
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>

<body>

<script type="text/babel">
// JSX Babel code goes here
</script>

</body>
</html>

What is Babel?

Babel is a JavaScript compiler that can translate markup or programming languages into JavaScript.

With Babel, you can use the newest features of JavaScript (ES6 - ECMAScript 2015).

Babel is available for different conversions. React uses Babel to convert JSX into JavaScript.

Please note that <script type="text/babel"> is needed for using Babel.

What is JSX?

JSX stands for JavaScript XML.

JSX is an XML/HTML like extension to JavaScript.

Example

const element = <h1>Hello World!</h1>

As you can see above, JSX is not JavaScript nor HTML.

JSX is a XML syntax extension to JavaScript that also comes with the full power of ES6 (ECMAScript 2015).

Just like HTML, JSX tags can have a tag names, attributes, and children.If an attribute is wrapped in curly braces, the value is a JavaScript expression.

Note that JSX does not use quotes around the HTML text string.

React DOM Render

The method ReactDom.render() is used to render (display) HTML elements:

Example

<div id="id01">Hello World!</div>

<script type="text/babel">
ReactDOM.render(
<h1>Hello React!</h1>,
document.getElementById('id01'));
</script>

Try it Yourself »

JSX Expressions

Expressions can be used in JSX by wrapping them in curly {} braces.

Example

<div id="id01">Hello World!</div>

<script type="text/babel">
const name = 'John Doe';
ReactDOM.render(
<h1>Hello {name}!</h1>,
document.getElementById('id01'));
</script>

Try it Yourself »

React Elements

React applications are usually built around a single HTML element.

React developers often call this the root node (root element):

<div id="root"></div>

React elements look like this:

const element = <h1>Hello React!</h1>

Elements are rendered (displayed) with the ReactDOM.render() method:

ReactDOM.render(element, document.getElementById('root'));

Try it Yourself »

React elements are immutable. They cannot be changed.

The only way to change a React element is to render a new element every time:

Example

function tick() {
const element = (<h1>{new Date().toLocaleTimeString()}</h1>);
ReactDOM.render(element, document.getElementById('root'));
}
setInterval(tick, 1000);

Try it Yourself »

React Components

React components are JavaScript functions.

This example creates a React component named "Welcome":

Example

function Welcome() {
return <h1>Hello React!</h1>;
}
ReactDOM.render(<Welcome />, document.getElementById('root'));

Try it Yourself »

React can also use ES6 classes to create components.

This example creates a React component named Welcome with a render method:

Example

class Welcome extends React.Component {
render() { return(<h1>Hello React!</h1>); }
}
ReactDOM.render(<Welcome />, document.getElementById('root'));

Try it Yourself »

React Component Properties

This example creates a React component named "Welcome" with property arguments:

Example

function Welcome(props) {
return <h1>Hello {props.name}!</h1>;
}
ReactDOM.render(<Welcome name="John Doe"/>, document.getElementById('root'));

Try it Yourself »

React can also use ES6 classes to create components.

This example also creates a React component named "Welcome" with property arguments:

Example

class Welcome extends React.Component {
render() { return(<h1>Hello {this.props.name}</h1>); }
}
ReactDOM.render(<Welcome name="John Doe"/>, document.getElementById('root'));

Try it Yourself »

JSX Compiler

The examples on this page compiles JSX in the browser.

For production code, the compilation should be done separately.

Create React Application

Facebook has created a Create React Application with everything you need to build a React app.

It is a a development server that uses Webpack to compile React, JSX, and ES6, auto-prefix CSS files.

The Create React App uses ESLint to test and warn about mistakes in the code.

To create a Create React App run the following code on your terminal:

Example

npx create-react-app react-tutorial

Make sure you have Node.js 5.2 or higher. Otherwise you must install npx:

Example

npm i npx

Start one folder up from where you want your application to stay:

Example

C:\Users\myUser>npx create-react-app react-tutorial

Success Result:

npx: installed 63 in 10.359s
Creating a new React app in C:\Users\myUser\react-tutorial.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
+ [email protected]
+ [email protected]
+ [email protected]
added 1732 packages from 664 contributors and audited 31900 packages in 355.501s
found 0 vulnerabilities+ [email protected]

Success! Created react-tutorial at C:\Users\myUser\react-tutorial
Inside that directory, you can run several commands:

npm start
Starts the development server.

npm run build
Bundles the app into static files for production.

npm test
Starts the test runner.

npm run eject
Removes this tool and copies build dependencies, configuration files
and scripts into the app directory. If you do this, you can't go back!

We suggest that you begin by typing:

cd react-tutorial
npm start


W3schools Pathfinder

Track your progress - it's free!

What is React (2024)

FAQs

What is React and why use it? ›

React is a framework that employs Webpack to automatically compile React, JSX, and ES6 code while handling CSS file prefixes. React is a JavaScript-based UI development library. Although React is a library rather than a language, it is widely used in web development.

What does React actually do? ›

React is a JavaScript library used for building user interfaces, especially for single-page applications where the user interacts with the web page without requiring a full page reload.

Is React a programming language? ›

React language is a component-based, open-source JavaScript library for front-end development. It is specifically used to build user interfaces for single-page applications. Before we get into further details, let's discuss what JavaScript library is, as it would help you get a better idea about React. js.

What is ReactJS mainly used for? ›

React. js, a frontend-focused JS library used mainly for building single-page and multi-page interfaces, is one of the most popular programming technologies worldwide, and the number of companies reaching out to it proves its solid position.

Why would anyone use React? ›

It allows you to determine how you want to handle routing, testing and even folder structure. Beyond the environment, the fact that React isn't too opinionated means it can be used on a host of different projects: web applications, static sites, mobile apps and even VR.

What is React not good for? ›

When you are making an app like a game or a demanding creative app, React is not the best choice. This problem stems from the fact that it uses a Virtual DOM. Virtual DOMs, or VDOMs, are layers that help make unoptimized DOM manipulations faster.

Is React very difficult? ›

Starting with React can be tough, especially if you're new to web development. Concepts like JSX, components, and state management might seem like a maze. But don't worry! With some practice and patience, it gets easier, and React becomes more familiar.

Does anyone use React anymore? ›

Well as far as I'm aware it's still the most popular frontend framework in use. Alongside with Vue. js and Angular, React is one of the tools that, when used properly, gives you a lot of fun and freedom creating extremely good web apps.

Is React easy to learn? ›

You might want to learn React but worry that it could be too hard. Thankfully, React is easy to learn, but only once you have foundational knowledge in JavaScript. Of course, the difficulty that comes with learning anything new is somewhat subjective.

Is React front-end or backend? ›

React is a front-end JavaScript library. React is capable of making API calls (sending the request to the backend), which deal with the data. React cannot process the database or the data source itself.

Can I learn React without knowing JavaScript? ›

In conclusion, while it is possible to learn React Native without prior knowledge of JavaScript, it is highly advisable to master JavaScript fundamentals first. A solid understanding of JavaScript will make your React Native learning journey smoother and more rewarding.

What problem does React solve? ›

React promotes the creation of reusable components, saving time and programmers' effort by eliminating the need to write repetitive code for the same features. Changes made to a particular component do not affect other parts of the application, ensuring a modular and maintainable codebase.

What is React basically used for? ›

React provides reusability of components, fast rendering, code stability, high performance, and extensive community support. It helps to create engaging user interfaces and cut back on development time. This is why React can be used for web apps and mobile development.

Which big company primarily uses React? ›

There are many top companies using React in their development process, such companies like AirBnB, Instagram, Netflix, Walmart, and the list goes endless. Keep reading because this blog can give you many insights and tricks that these companies have used while they use react for their business.

Why use React instead of JavaScript? ›

Why choose React over plain JavaScript for web development in 2024? React offers advantages like improved code organization, enhanced performance with the Virtual DOM, easier state management, and a thriving community, making it a powerful choice for modern web development projects.

Is React backend or frontend? ›

ReactJS is mainly a front-end open source and a JavaScript front-end library used for building the user interfaces of our web applications or websites. There are many alternatives to ReactJS, such as AngularJs and VueJs.

Why is React better than Python? ›

Web applications built with ReactJS code are more efficient, operate quicker, and can handle much data. In contrast, Python web development takes a while to react. ReactJS has many advantages in this area because of the synchronous nature of the most effective frameworks, which provide high-end app capacity.

Top Articles
What is Debt Finance? Definition of Debt Finance, Debt Finance Meaning - The Economic Times
Mastering The Art Of Graceful Departures: How and When To Walk Away
This website is unavailable in your location. – WSB-TV Channel 2 - Atlanta
Television Archive News Search Service
Hertz Car Rental Partnership | Uber
Bed Bath And Body Works Hiring
State Of Illinois Comptroller Salary Database
Boat Jumping Female Otezla Commercial Actress
Uvalde Topic
Craigslist Estate Sales Tucson
Jscc Jweb
Void Touched Curio
Belle Delphine Boobs
065106619
Busby, FM - Demu 1-3 - The Demu Trilogy - PDF Free Download
Wicked Local Plymouth Police Log 2022
Velocity. The Revolutionary Way to Measure in Scrum
Craigslist Red Wing Mn
Directions To Advance Auto
Mission Impossible 7 Showtimes Near Marcus Parkwood Cinema
Byui Calendar Fall 2023
Buy Swap Sell Dirt Late Model
Weepinbell Gen 3 Learnset
Glenda Mitchell Law Firm: Law Firm Profile
Music Go Round Music Store
Somewhere In Queens Showtimes Near The Maple Theater
Routing Number For Radiant Credit Union
Buying Cars from Craigslist: Tips for a Safe and Smart Purchase
T Mobile Rival Crossword Clue
Aspenx2 Newburyport
2487872771
Hellraiser 3 Parents Guide
European Wax Center Toms River Reviews
2023 Ford Bronco Raptor for sale - Dallas, TX - craigslist
Craigslist Fort Smith Ar Personals
Lcsc Skyward
San Jac Email Log In
Courtney Roberson Rob Dyrdek
134 Paige St. Owego Ny
Ippa 番号
9781644854013
Fwpd Activity Log
Trivago Sf
Coroner Photos Timothy Treadwell
Unveiling Gali_gool Leaks: Discoveries And Insights
Oklahoma City Farm & Garden Craigslist
The Machine 2023 Showtimes Near Roxy Lebanon
Dmv Kiosk Bakersfield
Immobiliare di Felice| Appartamento | Appartamento in vendita Porto San
Chitterlings (Chitlins)
Tweedehands camper te koop - camper occasion kopen
Latest Posts
Article information

Author: Greg O'Connell

Last Updated:

Views: 6065

Rating: 4.1 / 5 (62 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Greg O'Connell

Birthday: 1992-01-10

Address: Suite 517 2436 Jefferey Pass, Shanitaside, UT 27519

Phone: +2614651609714

Job: Education Developer

Hobby: Cooking, Gambling, Pottery, Shooting, Baseball, Singing, Snowboarding

Introduction: My name is Greg O'Connell, I am a delightful, colorful, talented, kind, lively, modern, tender person who loves writing and wants to share my knowledge and understanding with you.