How To Develop and Build React App With .NET Core Backend
Learn How you develop and build with an example project

There are so many ways we can build React apps and ship them for production. One way is to build React with Nodejs, Java, or .NET and another way is to build the React and serve that static content with NGINX web server. With .NET we have to deal with the server code as well, for example, you need to load the index.html page with .NET core
In this post, we will see the details and implementation with .NET Core. We will go through step by step with an example.
- Introduction
- Prerequisites
- Example Project
- How To Build and Develop The Project
- Interaction Between React and .NET API
- How To Build For Production
- Summary
- Conclusion
Introduction
React is a javascript library for building web apps and it doesn’t load itself in the browser. We need some kind of mechanism that loads the index.html (single page) of React with all the dependencies(CSS and js files) in the browser. In this case, we are using .NET Core Web API which loads React assets and accepts any API calls from the React app.

If you look at the above diagram all the web requests without the /api will go to React routing. All the paths that contain /api will be handled by the .NET Core API.
Prerequisites
There are some prerequisites for this article. You need to have .NET Core installed on your laptop and how http works. If you want to practice and run this on your laptop you need to have these on your laptop.
You can check the .NET Core version with the following command once it is installed.
dotnet --versionIf you are not familiar with React library. I would recommend you go through the below article.
Example Project
This is a simple project which demonstrates developing and running a React application with the .NET. We have a simple app in which we can add users, count, and display them at the side, and retrieve them whenever you want.

As you add users we are making an API call to the .NET Core API to store them and get the same data from the server when we retrieve them. You can see network calls in the following video.

Here is a Github link to this project. You can clone it and run it on your machine.
// clone the project
git clone https://github.com/bbachi/react-dotnet-example.git// run the project
cd react-dotnet-example
dotnet runHow To Build and Develop The Project
Usually, the way you develop and the way you build and run in production are completely different. Thatswhy, I would like to define two phases: The development phase and the production phase.
Once you have installed the .NET SDK on your machine, you can generate the whole project (React + .NET Core ) template with this command.
dotnet new react -o <project name>
React App
Here is the generated template project. All the React code resides under the ClientApp folder. From Microsoft Docs, The project template creates an ASP.NET Core app and a React app. The ASP.NET Core app is intended to be used for data access, authorization, and other server-side concerns. The React app, residing in the ClientApp subdirectory, is intended to be used for all UI concerns.

Let’s implement the React App first. As long as NodeJS installed on your machine you can change the directory and you can run any npm commands.
If you look at the package.json from the generated React project .NET SDK creates a React template with version 16.














