Introduction to React.js

Hello, and welcome to your first journey into the world of React.js! So, what exactly is React.js? Simply put, it's a JavaScript library used to build user interfaces, specifically for single-page applications.

Websites today are not just simple pages with text and images anymore; they are full-blown applications that rerender, interact with the user, and update live without refreshing the page.

With regular HTML and JavaScript, when we want to update the user interface according to user action or other events, we manually manipulate the DOM and update the required elements. However, with React.js, we divide our user interface into separate reusable components, and React.js effectively decides what parts of the user interface need to be updated when the application's state changes. This approach makes the code cleaner, easier to understand and maintain, and more efficient.

Are you excited? We certainly are. Let's get started!

Introduction to JSX

React introduces a syntax that looks like a combination of JavaScript and HTML. This syntax, known as JSX (JavaScript XML), allows developers to build HTML structures directly within their JavaScript code.

Consider this simple example:

In this code, element is not a string or HTML - it's a JSX element. It seems like a string of HTML, but technically, it's a JavaScript object representing a 'H1' HTML element in memory (often referred to as "Virtual DOM").

Embedding JavaScript Expressions

With JSX, you're not limited to static HTML-like tags, you can embed JavaScript expressions as well:

In this example, a + b is a JavaScript expression embedded in JSX. When React renders this component, it will replace with the result of the expression, displaying 'The sum is: 30' on the screen.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal