Loading

Quipoin Menu

Learn • Practice • Grow

react / Introduction to React
tutorial

Introduction to React

Imagine you are building a house. You could build everything from scratch—mix cement, lay bricks one by one, install every pipe and wire yourself. That would take forever and be incredibly difficult. Instead, you use pre-built rooms called components—a kitchen module, a bathroom unit, pre-fabricated walls. You just assemble them together. That's exactly what React does for web development.

React is a JavaScript library created by Facebook (now Meta) in 2013 for building user interfaces, especially single-page applications where you need a fast, interactive experience. Before React, updating a webpage meant reloading the whole page or writing complex JavaScript to manually change individual elements. React changed the game by introducing a component-based architecture and a Virtual DOM.

Why Did React Come?

Before React, developers faced several challenges:

  • Complex DOM Manipulation: Updating the UI required manually selecting elements and changing them, which was error-prone and slow.
  • Performance Issues: Every small change often required the entire page to re-render, hurting performance.
  • Code Maintainability: As applications grew, spaghetti code became common—HTML, CSS, and JavaScript were all mixed up.

React solved these by introducing a new way to think: build your UI as a tree of components, and let React handle the updates efficiently.

What is React?

React is a JavaScript library for building user interfaces. It is:

  • Component-Based: You build encapsulated components that manage their own state, then compose them to make complex UIs.
  • Declarative: You tell React what you want the UI to look like, and React figures out how to update the DOM efficiently.
  • Learn Once, Write Anywhere: You can develop new features in React without rewriting existing code, and you can even use React on the server with Next.js or for mobile apps with React Native.

Core Features of React

1. Components
Components are the building blocks of any React application. A component is a JavaScript function or class that optionally accepts inputs (called 'props') and returns a React element that describes how a section of the UI should appear.

2. JSX
JSX is a syntax extension for JavaScript that looks similar to HTML. It makes writing React components easier and more readable. Instead of separating markup and logic in different files, React uses components that contain both.

3. Virtual DOM
The Virtual DOM is a lightweight copy of the actual DOM kept in memory. When a component's state changes, React updates the Virtual DOM first, then compares it with the previous version (a process called 'diffing'), and finally updates only the changed parts in the real DOM. This makes updates extremely fast.

4. One-Way Data Flow
Data in React flows from parent to child components via props. This makes the application more predictable and easier to debug.

Simple Example

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

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Welcome name="Sara" />);

This simple example shows a 'Welcome' component that accepts a 'name' prop and renders a greeting. React then renders this component into the DOM.

Two Minute Drill

  • React is a JavaScript library for building user interfaces, created by Facebook in 2013.
  • It uses a component-based architecture where UIs are built from reusable pieces called components.
  • React is declarative: you describe what you want, and React handles the DOM updates efficiently.
  • Key features include JSX (HTML-like syntax), Virtual DOM for performance, and one-way data flow.
  • React solves problems of complex DOM manipulation, poor performance, and code maintainability in large applications.
  • You can use React for web (ReactDOM), mobile (React Native), and server-side rendering (Next.js).

Need more clarification?

Drop us an email at career@quipoinfotech.com