Introduction
React is a trendy JavaScript library to create the UI. React is straightforward to learn and create reusable web components. But similar to other JavaScript library/framework it has one major drawback that is doesn’t provide the server-side rendering. Actually, React uses the Virtual DOM ideology that is a wrapper to Real DOM. It is very necessary because it makes rendering very fast and prevent the extra and not required DOM operation and make application fast. But as we know that in this world nothing is 100% perfect each new thing comes with some side effects or loopholes. Or we can say that every great thing comes with some price.
The same is with the Virtual DOM concept, it reduces the DOM operations and makes the application faster but it doesn’t provide the server-side rendering. What is mean by server-side rendering?

When we create any React application and display some content in application it only displays on the browser and data is lost from the server.
Does it matter for us?

If you are thinking that you can create React app and make them live then why server-side rendering matter so much. Let’s take an example. I create a simple React application with some controls like below.

In this application, I create a label, textbox, and a button. Let’s check the page source of this application. The page source of the above screen will be following,

You go through this screen you don’t find anything related to screen that we are displaying on the browser. That is because React doesn’t create any Real DOM it only creates the virtual DOMS. So whenever Search Engine Crawlers search for this page they don’t find anything on this page. Because Crawler never considers what terminology or ideology you are using to create the application. Crawler only looks for the content of the page. No content is available on the site the indexing of the site will never be created by the Crawler.
There are other use cases where React fails to complete the requirement. If an application is created using the React and we try to share the application on any Media platform like Twitter or Facebook, then you don’t find the exact result you want because all media platforms only render the data from the server.
If you are going to create a long page then it can take a long time to display the data because React first load all the JavaScript code then make it display to the user. There is not any concept like early loading.
In the React world, there is the superhero that name is Next.js. Our superhero Next.js can save us from this trouble. Let’s take an intro about Next.js.

Next.js
Next.js is a popular React.js Framework that enables the server-side rendering and also provides some other useful features for React application. In other words, using the Next.js we can create a Universal app that can render both on client and server-side.
Features of Next.js
- Hot Code Reloading - Next.js re-render the page whenever it detects any pages into the page.
- Zero configuration and Single command setup - Don’t need bulk line of code to set up, we can setup a project with the single-line command.
- Single File Components - Next.js use the styled-jsx that provide the provide scoped and component-friendly CSS support for JSX (rendered on the server or the client).
- Server-Side Rendering - We can render the React component on a server before sending it to the client.
- Automatic Routing - We don’t need to perform routing manually, all components in the Pages folder are automatically attached to the URL.
- Ecosystem Compatibility - Next.js is easy to configure and work with the rest of JavaScript, React, and Node.js ecosystem.
- Automatic Code splitting - Next.js only rendered the required modules and libraries, not all at a time.
- Prefetching - Next.js support prefetching that prefetch the page resources in the background.
- Dynamic Component - We can import the React component and modules dynamically also.
- Static Exports - Next provide a “next export” command using that we can export a static site for our application.
Installation
As we say that Next.js setup is just one line command. Create a directory and name it whatever you want. Here I named my folder “NextJsApp”, after creating the folder not move this folder and open the command prompt and run below command.
First, run the “npm init –yes” in the terminal, this command will create a package.json file. Now run the below command.
npm install --save next react react-dom
Above command install the basic required dependency. After installing the required modules now add below line of code in packages.json scripts sections.
"start": "next"
Now run the below command in terminal
“npm run start”.
As you run the above command you will get some errors related the “pages” directory.

The reason is that Next.js required a “pages” directory into the root of the application. In this directory, we will create all the URI components. Let’s create a “pages” directory and run the command again.

This time Next.js start the server successfully at 3000 port’ let’s access this URL and check what happens. If we try to access the “localhost:3000” URL we will get the following output.







Sanele S'phonikPosted Jul 22, 2020, 10:23 PM
How can I integrate next.js to the react asp.net core project template?
E NielsenPosted May 24, 2020, 8:42 PM
Great job. But, you have "cons" and "pros" switched. con=bad pro=good.