What is React?

React is a JavaScript library developed by Facebook to make user interface. particularly the single-page applications. It lets us create reusable components that can efficiently update and render when our data changes.

React solves a fundamental problem in web development. Traditionally, updating web pages required manually manipulating the DOM, which was error-prone and inefficient. React introduces a 'Virtual DOM' and declarative approach where you just describe what you want the UI to look like, and React efficiently handles all the DOM updates for you

What is Single Page Application (SPA)

An SPA is a web application that uses only one HTML page and dynamically updates the content as the user interacts with the website. so, instead of loading an entirely new page from the server, it just updates the necessary parts of the existing page creating a more fluid, app-like experience.

React is a single-page application. In any pre-react website, if I click on something let’s say a message tab, when I click a new index.html page will come in there will be a hard reload on the browser. React lets you create a single-page application. All the code comes in the first go itself, there is no need to hard-reload. React uses the concept of client-side routing for this feature.

However, a disadvantage is that initial loading takes longer since the entire application must be downloaded. Additionally, it negatively impacts the website's SEO performance.

Declarative Programming (React Feature)

Developers describe what the UI should look like for a given state, and React handles the necessary updates to the actual display. This makes the code more predictable and easier to debug, as you don't need to write step-by-step instructions for every UI change.

Components

Components are the fundamental building blocks of React applications. Think of Instagram's feed as an example - each post you see is actually a reusable component. Let me break this down:

function Post({ author, content, likes, comments }) {
  return (
    <div className="post">
      <PostHeader author={author} />
      <PostContent content={content} />
      <EngagementBar likes={likes} />
      <CommentSection comments={comments} />
    </div>
  );
}

The postcard can serve as a major component that nests other components mentioned earlier. This component-based approach offers several advantages:

  1. Reusability: All posts in the application are defined only once; the component simply displays different text and images each time.
  2. Modularity: This is a core principle in the world of development. From language syntax to large microservice architectures, this principle helps manage various elements effectively.

JSX in Components

JSX is a syntax extension for JavaScript that allows you to write HTML-like syntax within your JavaScript code. React components are created using JSX, as it enables you to define HTML structures easily.

Virtual DOM vs Browser DOM