{"id":85124,"date":"2019-08-30T17:48:35","date_gmt":"2019-08-30T17:48:35","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=85124"},"modified":"2026-04-15T18:27:16","modified_gmt":"2026-04-15T18:27:16","slug":"creating-asp-net-apps-with-react","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/development\/dotnet-development\/creating-asp-net-apps-with-react\/","title":{"rendered":"ASP.NET Core Web API with React Frontend: Setup and Integration Guide"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-executive-summary\">Executive Summary<\/h2>\n\n\n\n<p><strong>This article walks through connecting an ASP.NET Core Web API backend to a React frontend &#8211; a common architecture for modern .NET web applications. The back-end is a Visual Studio ASP.NET Core API project exposing REST endpoints. The front-end is a React app using Reactstrap (Bootstrap 4 components for React) for responsive UI. Both projects run independently and communicate over HTTP. You will set up both projects from scratch, build a simple UI with header and footer components, and make API calls from React to the ASP.NET Core API.<\/strong><\/p>\n\n\n\n<p>Single Page Applications are the new wave of the moment. In the midst of several frameworks and libraries that arose during the last decade to tackle better ways to build web applications, <a href=\"https:\/\/reactjs.org\/\">React<\/a> is now the most popular one. It\u2019s a lightweight library (yes, React is not a framework, so it means it doesn\u2019t come with all the rules, specifications and patterns that Angular, e.g., comes with), that is embraced and powered by the community, simple to use, flexible, and relies on a strong concept: components.<\/p>\n\n\n\n<p>Components are not a concept created by React, you may say, and you would be correct. However, React made them far simpler for JavaScript developers. Now, with just the use of a single <em>.js<\/em> file, as well as the power of ECMAScript (especially from 6+) and some good old patterns, you can create complex web applications from scratch, reusing as many components you need. This makes the reuse of code a big plus for JavaScript apps: more testable, concise, understandable, etc.<\/p>\n\n\n\n<p>Besides that, the community grew rapidly around the React world, creating tons of new related libraries that help to boost React\u2019s power to a whole new level. From libs for centralized state management (Redux), stylizing your components (or add known libs like Bootstrap, Antd, etc.), to completely new ways of dealing with forms, remote calls, server-side rendering\u2026 The number of options is huge and continuously growing.<\/p>\n\n\n\n<p>In this article, you\u2019ll learn how to integrate a well-known back-end API (that\u2019ll be served on top of ASP.NET) to a SPA totally made in React from scratch. React, in fact, can be integrated with whatever back-end services you want; however, this will be an excellent opportunity for you to analyze how both environments (front and back) work together in real-world scenarios.<\/p>\n\n\n\n<p>To do this, the article covers building a CRUD application of user data, exploring the construction of both back and front ends, from the installation and configuration to the implementation. It makes use of Bootstrap for the UI, in order to cut down on worry about CSS and styles. This is the final representation of the view, once done:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1300\" height=\"858\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/08\/https-lh5-googleusercontent-com-wb9c4_vek7vffkc1.png\" alt=\"https:\/\/lh5.googleusercontent.com\/wb9C4_vEk7vFfkC1kTt4qxQ_9H6i2_T-EsWdjwNO77J1QH6HEiwGkdcznWR13xKu6c6VKOAHz-JxIKV_KNQZMnCpdnqMzwaQPT6zCLwIW5bGgrZ6LiEyYg3bh6vE2z9dff28jKEr\" class=\"wp-image-85125\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"caption\">Figure 1. The final application visualization.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-setup-back-end\">Setup \u2013 Back-end<\/h2>\n\n\n\n<p>First, make sure you have a recent version of Visual Studio Community installed on your computer. Then, create an API project by going to the <em>File &#8211;&gt; New &#8211;&gt; Project\u2026<\/em> menu and selecting the <em>ASP.NET Core Web Application<\/em> option, as shown in Figure 2.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1178\" height=\"816\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/08\/word-image-85.png\" alt=\"\" class=\"wp-image-85126\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"caption\">Figure 2. Creating the new API project.<\/p>\n\n\n\n<p>Give it a name and click <em>OK<\/em>. For the next wizard screen, you\u2019re going to see that a <em>React.js<\/em> project template is already available along with the ASP.NET Core projects. It\u2019s useful to have this, mainly for experienced developers who don\u2019t want to spend much time on setting up and copy-pasting stuff. However, as beginners, I\u2019d suggest starting from zero, with preset config. This will lead you a better understanding of the basics around how React works, as well as how you will connect the front to the back-end API.<\/p>\n\n\n\n<p>Additionally, this example will not use the same structure VS sets up there. It consists of a project in which the front will be hosted the same place as the back-end code. Nevertheless, you will work in a side front project independent of the ASP.NET suite. This means that they\u2019ll exist in two different worlds that still communicate with each other.<\/p>\n\n\n\n<p>After completing this tutorial, I\u2019d encourage you to go back and create another project, this time, with the project template. That way, you\u2019ll have enough knowledge to understand what VS has magically created for you.<\/p>\n\n\n\n<p>Once finished, move on to the ASP.NET API architecture. This is going to be simple: you\u2019ll expose some <em>\/users<\/em> endpoints to add, list, search, update and delete users in an in-memory static list in the back-end application. This way, you\u2019ll maintain three main packages in the project:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li><em>Controllers<\/em>: already created within the project, they\u2019ll store the user\u2019s controller;<\/li>\n\n\n\n<li><em>Models<\/em>: will store the data transfer objects, as plain and simple user data objects;<\/li>\n\n\n\n<li><em>Services<\/em>: will store the service classes that\u2019ll handle the operations over the user\u2019s list.<\/li>\n<\/ul>\n<\/div>\n\n\n<p>Make sure to create each folder in the root source folder. Start with the <em>User.cs<\/em> file. Listing 1 shows its content.<\/p>\n\n\n\n<p class=\"caption\">Listing 1. User.cs class<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">using System;\nnamespace ReactASPCrud.Models\n{\n    public class User\n    {\n        public int Id { get; set; }\n        public string Name { get; set; }\n        public string Email { get; set; }\n        public string Document { get; set; }\n        public string Phone { get; set; }\n    }\n}<\/pre>\n\n\n\n<p>It\u2019s just simple code with a bunch of fields to represent each input shown in Figure 1.<\/p>\n\n\n\n<p>Listing 2 shows how the <em>UserService.cs<\/em> will look:<\/p>\n\n\n\n<p class=\"caption\">Listing 2. UserService.cs class code.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">using ReactASPCrud.Models;\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nnamespace ReactASPCrud.Services\n{\n    public class UserService\n    {\n        private static List&lt;User&gt; users = new List&lt;User&gt;();\n        private static int Count = 1;\n        private static readonly string[] names = new string[] { \"Jonathan\", \"Mary\", \"Susan\", \"Joe\", \"Paul\", \"Carl\", \"Amanda\", \"Neil\" };\n        private static readonly string[] surnames = new string[] { \"Smith\", \"O'Neil\", \"MacDonald\", \"Gay\", \"Bailee\", \"Saigan\", \"Strip\", \"Spenser\" };\n        private static readonly string[] extensions = new string[] { \"@gmail.com\", \"@hotmail.com\", \"@outlook.com\", \"@icloud.com\", \"@yahoo.com\" };\n        static UserService()\n        {\n            Random rnd = new Random();\n            for (int i = 0; i &lt; 5; i++)\n            {\n                string currName = names[rnd.Next(names.Length)];\n                User user = new User\n                {\n                    Id = Count++,\n                    Name = currName + \" \" + surnames[rnd.Next(surnames.Length)],\n                    Email = currName.ToLower() + extensions[rnd.Next(extensions.Length)],\n                    Document = (rnd.Next(0, 100000) * rnd.Next(0, 100000)).ToString().PadLeft(10, '0'),\n                    Phone = \"+1 888-452-1232\"\n                };\n                users.Add(user);\n            }\n        }\n        public List&lt;User&gt; GetAll()\n        {\n            return users;\n        }\n        public User GetById(int id)\n        {\n            return users.Where(user =&gt; user.Id == id).FirstOrDefault();\n        }\n        public User Create(User user)\n        {\n            user.Id = Count++;\n            users.Add(user);\n            return user;\n        }\n        public void Update(int id, User user)\n        {\n            User found = users.Where(n =&gt; n.Id == id).FirstOrDefault();\n            found.Name = user.Name;\n            found.Email = user.Email;\n            found.Document = user.Document;\n            found.Phone = user.Phone;\n        }\n        public void Delete(int id)\n        {\n            users.RemoveAll(n =&gt; n.Id == id);\n        }\n    }\n}<\/pre>\n\n\n\n<p>There are a couple of new things going on. First, you need a static <code>List<\/code> to store the elements, simulating something like a database (feel free to implement whatever storage strategy you would like). The next three arrays represent some random names, surnames and mail extensions in order to facilitate the process of generating a prelist of users and randomize their field values as well.<\/p>\n\n\n\n<p>The static block initializes this list, making sure to generate as many random values as possible. The rest of the methods are just performing usual operations over the list, with the help of <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/programming-guide\/concepts\/linq\/\">Linq<\/a>.<\/p>\n\n\n\n<p>Simple, isn\u2019t it? Time to move to the controller. Make sure to rename the default one already created to <em>UsersController.cs<\/em> (the plural is important here, once it\u2019s used for ASP.NET to apply the URI path for all operations). Then, substitute its content with the code shown in Listing 3.<\/p>\n\n\n\n<p class=\"caption\">Listing 3. UsersController.cs class code.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">using System.Collections.Generic;\nusing System.Threading.Tasks;\nusing Microsoft.AspNetCore.Cors;\nusing Microsoft.AspNetCore.Mvc;\nusing ReactASPCrud.Models;\nusing ReactASPCrud.Services;\nnamespace ReactASPCrud.Controllers\n{\n    [Produces(\"application\/json\")]\n    [Route(\"api\/[controller]\")]\n    [ApiController]\n    [EnableCors(\"ReactPolicy\")]\n    public class UsersController : ControllerBase\n    {\n        private readonly UserService userService;\n        public UsersController(UserService userService)\n        {\n            this.userService = userService;\n        }\n        \/\/ GET api\/users\n        [HttpGet]\n        public IEnumerable&lt;User&gt; Get()\n        {\n            return userService.GetAll();\n        }\n        \/\/ GET api\/users\/5\n        [HttpGet(\"{id}\")]\n        public async Task&lt;IActionResult&gt; Get(int id)\n        {\n            return Ok(userService.GetById(id));\n        }\n        \/\/ POST api\/users\n        [HttpPost]\n        public async Task&lt;IActionResult&gt; Post([FromBody] User user)\n        {\n            return CreatedAtAction(\"Get\", new { id = user.Id }, userService.Create(user));\n        }\n        \/\/ PUT api\/users\/5\n        [HttpPut(\"{id}\")]\n        public async Task&lt;IActionResult&gt; Put(int id, [FromBody] User user)\n        {\n            userService.Update(id, user);\n            return NoContent();\n        }\n        \/\/ DELETE api\/users\/5\n        [HttpDelete(\"{id}\")]\n        public async Task&lt;IActionResult&gt; Delete(int id)\n        {\n            userService.Delete(id);\n            return NoContent();\n        }\n        public override NoContentResult NoContent()\n        {\n            return base.NoContent();\n        }\n    }\n}<\/pre>\n\n\n\n<p>Note that most operations perform the exact same calls through the <code>UserService<\/code> methods; they\u2019re practically equal. However, some things are noticeable:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li><code>EnableCors<\/code> annotation is an important point here, mainly because it sets the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/CORS\">CORS<\/a> policy this controller must use, the one to be configured soon. Without it, request calls from a different origin (the React application, in this case) won\u2019t be allowed by the server;<\/li>\n\n\n\n<li>The service is being injected via the controller\u2019s constructor. This is only possible because you\u2019ll also set it up soon in the Startup class;<\/li>\n\n\n\n<li>The <em>Post<\/em> method makes use of <code>CreatedAtAction()<\/code> method to return a reference to the <code>Get<\/code> equivalent method of the then-created user. This allows the API to return a 201 HTTP status along with the header of where the created resource is located;<\/li>\n\n\n\n<li>The rest of the endpoints return a 204 HTTP status representing a <em>No Content<\/em> action.<\/li>\n<\/ul>\n<\/div>\n\n\n<p>Finally, you need to make some important configurations to the <em>Startup.cs<\/em> class. Open it and add the following changes shown in Listing 4. These are the code you need to add to the <code>ConfigureServices()<\/code> method:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li>The registration of <code>UserService<\/code> as a singleton object that\u2019ll be automatically available for injection throughout the project;<\/li>\n\n\n\n<li>The Cors policy previously mentioned. Here, you\u2019re just allowing any method, origin, header and credentials that arrive at the house (which wouldn\u2019t be appropriate for production security reasons).<\/li>\n<\/ul>\n<\/div>\n\n\n<p class=\"caption\">Listing 4. Code to add to <em>ConfigureServices()<\/em> method.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">using ReactASPCrud.Services\n\u2026\nservices.AddSingleton&lt;UserService&gt;();\nservices.AddCors(o =&gt; o.AddPolicy(\"ReactPolicy\", builder =&gt;\n{\n     builder.AllowAnyOrigin()\n            .AllowAnyMethod()\n            .AllowAnyHeader()\n            .AllowCredentials();\n}));<\/pre>\n\n\n\n<p>Then, you need to make sure that the Cors is enabled by adding the following code snippet to the <code>Configure()<\/code> method:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">app.UseCors(\"ReactPolicy\");<\/pre>\n\n\n\n<p>Now you can run the application and the test the endpoints on your own. Make sure to pay attention to the port where your service will be run since this is going to be important when calling the endpoints from the React code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-setup-front-end\">Setup \u2013 Front-end<\/h2>\n\n\n\n<p>Now, it\u2019s React time. The first thing you must install on your computer is Node.js. I\u2019m not getting into details about Node.js and how it works or how to install it, but if you don\u2019t have it yet, follow this <a href=\"https:\/\/nodejs.org\/en\/download\/\">link for instructions<\/a>. It\u2019s very straightforward. Please, remember that, for this article, you\u2019ll need a Node.js at, at least, 8.16.0+. So, make sure to upgrade it if you\u2019re under an older version.<\/p>\n\n\n\n<p>For the IDE, use <a href=\"https:\/\/code.visualstudio.com\/\">Visual Studio Code<\/a> for the front-end, but feel free to use whichever tool you\u2019re more used to.<\/p>\n\n\n\n<p>Because of the complexities involving React, use <a href=\"https:\/\/github.com\/facebook\/create-react-app\">create-react-app<\/a>, a great shortcut to creating a preset React application that comes with default folders, initial config files, <em>serviceWorker<\/em>, a <em>package.json<\/em> file, some JavaScript\/CSS files and more. It makes it very easy to create an application from nothing and run it with npm or yarn.<\/p>\n\n\n\n<p>The first command you need to run is the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">npx create-react-app react-ui-crud<\/pre>\n\n\n\n<p><a href=\"https:\/\/www.npmjs.com\/package\/npx\">npx<\/a> is a tool that facilitates using packages from the npm registry. Npm is a better way to deal with dependencies on the registry, and so it is the same for npx for CLI tools\/executables on the registry. You can read more about it <a href=\"https:\/\/medium.com\/@maybekatz\/introducing-npx-an-npm-package-runner-55f7d4bd282b\">here<\/a>.<\/p>\n\n\n\n<p>The first limitation is the name of the project. There are some restrictions like the use of capital letters or special characters. Once you enter the command, some basic React dependencies will be immediately installed:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/facebook\/react\">react<\/a>: the React lib itself. Main module;<\/li>\n\n\n\n<li><a href=\"https:\/\/www.npmjs.com\/package\/react-dom\">react-dom<\/a>: this package serves as the entry point to the DOM and server renderers for React. It is intended to be paired with the generic React package, which is shipped as react to npm.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.npmjs.com\/package\/react-scripts\">react-scripts<\/a>: this package includes scripts and configuration used by Create React App.<\/li>\n<\/ul>\n<\/div>\n\n\n<p>At the end, the script will have created your project with the following structure:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"405\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/08\/structure.png\" alt=\"\" class=\"wp-image-85133\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The <em>node_modules<\/em> is the directory where all your Node.js dependencies will be installed. They\u2019re going to be read from the <em>package.json<\/em> file, which instructs npm to handle what packages retrieve from the registry (remote repo) every time you run the command <em>npm start<\/em>. That\u2019s why this directory is usually ignored in your <em>.gitignore<\/em> file, once npm knows where to search for all of them in case you\u2019re cloning the project for the first time or accidentally delete them.<\/p>\n\n\n\n<p>The <em>public<\/em> folder is the place you\u2019ll store the files that can be directly accessed from the client, like images, HTML or public scripts. Generally, the <em>src<\/em> folder, the one that stores your JavaScript dynamic files as well as CSS, is the folder where you spend most of the time working.<\/p>\n\n\n\n<p>Figure 3 shows the output generated by the command.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1103\" height=\"993\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/08\/word-image-86.png\" alt=\"\" class=\"wp-image-85127\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"caption\">Figure 3. create-react-app output.<\/p>\n\n\n\n<p>You still need to add some more dependencies to the project. Since you won\u2019t take too much time on the styling of the UI, you\u2019ll make use of Bootstrap for that job. More specifically, you\u2019ll use the <a href=\"https:\/\/reactstrap.github.io\/\">reactstrap library<\/a>, which is a great encapsulation of Bootstrap components as React ones.<\/p>\n\n\n\n<p>For this, issue the following command in the root folder of the project:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">npm install --save bootstrap reactstrap<\/pre>\n\n\n\n<p>That\u2019s it. Before diving into the React code, analyze the contents of <em>package.json<\/em> file in Listing 5.<\/p>\n\n\n\n<p class=\"caption\">Listing 5. package.json code.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n  \"name\": \"react-ui-crud\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"react\": \"^16.8.6\",\n    \"react-dom\": \"^16.8.6\",\n    \"react-scripts\": \"3.0.1\",\n    \"reactstrap\": \"^8.0.1\"\n  },\n  \"scripts\": {\n    \"start\": \"react-scripts start\",\n    \"build\": \"react-scripts build\",\n    \"test\": \"react-scripts test\",\n    \"eject\": \"react-scripts eject\"\n  },\n  \"eslintConfig\": {\n    \"extends\": \"react-app\"\n  },\n  \"browserslist\": {\n    \"production\": [\n      \"&gt;0.2%\",\n      \"not dead\",\n      \"not op_mini all\"\n    ],\n    \"development\": [\n      \"last 1 chrome version\",\n      \"last 1 firefox version\",\n      \"last 1 safari version\"\n    ]\n  }\n}<\/pre>\n\n\n\n<p>The main parts of the file are contained under <code>dependencies<\/code> and <code>scripts<\/code> properties. The first lists the exactly same dependencies previously installed (this is part of the way npm knows where to fetch again in case you delete them); the second configures the commands npm used when you run <code>start<\/code>, <code>build<\/code>, etc. along with <code>npm<\/code> in the command line.<\/p>\n\n\n\n<p>Go and test it. Run <code>npm start<\/code> in the root folder, and npm will run the application, as well as open a browser window with a simple logo of React and some code as an example.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-let-s-react\">Let\u2019s React<\/h2>\n\n\n\n<p>First take a look at the usual header and footer parts. It\u2019s easier since you\u2019ll have contact with the menu and footer links first and understand how you can connect Bootstrap with React. For this, create a new folder <em>\/components<\/em> into <em>\/src<\/em> folder, which is the place to store all the scripts regarding React components. Then, create two files <em>AppHeader.js<\/em> and <em>AppFooter.js<\/em>. Listing 6 shows the code of the first JavaScript file.<\/p>\n\n\n\n<p class=\"caption\">Listing 6. First React component: AppHeader.js<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import React, { Component } from 'react'; \/\/ 1\nimport {\n    Navbar,\n    NavbarBrand,\n    NavbarToggler,\n    Collapse,\n    Nav,\n    NavItem,\n    NavLink,\n    UncontrolledDropdown,\n    DropdownToggle,\n    DropdownMenu,\n    DropdownItem\n} from 'reactstrap'; \/\/ 2\nclass AppHeader extends Component { \/\/ 3\n    state = { \/\/ 4\n        isOpen: false\n    };\n    toggle = this.toggle.bind(this); \/\/ 5\n    toggle() { \/\/ 6\n        this.setState({\n            isOpen: !this.state.isOpen\n        })\n    }\n    render() { \/\/ 7\n        return &lt;Navbar color=\"dark\" dark expand=\"md\"&gt;\n            &lt;NavbarBrand href=\"\/\"&gt;\n                &lt;img src=\"https:\/\/cdn.rd.gt\/assets\/images\/global\/redgate-logo--white.svg?v=1\" width=\"128\" className=\"d-inline-block align-top\" alt=\"\" \/&gt;\n            &lt;\/NavbarBrand&gt;\n            &lt;NavbarToggler onClick={this.toggle} \/&gt;\n            &lt;Collapse isOpen={this.state.isOpen} navbar&gt;\n                &lt;Nav className=\"ml-auto\" navbar&gt;\n                    &lt;NavItem&gt;\n                        &lt;NavLink href=\"\/\"&gt;Hello&lt;\/NavLink&gt;\n                    &lt;\/NavItem&gt;\n                    &lt;UncontrolledDropdown nav inNavbar&gt;\n                        &lt;DropdownToggle nav caret&gt;\n                            World\n                        &lt;\/DropdownToggle&gt;\n                        &lt;DropdownMenu right&gt;\n                            &lt;DropdownItem href=\"\/\"&gt;For U&lt;\/DropdownItem&gt;\n                            &lt;DropdownItem&gt;For Us&lt;\/DropdownItem&gt;\n                        &lt;\/DropdownMenu&gt;\n                    &lt;\/UncontrolledDropdown&gt;\n                &lt;\/Nav&gt;\n            &lt;\/Collapse&gt;\n        &lt;\/Navbar&gt;;\n    }\n}\nexport default AppHeader; \/\/ 8<\/pre>\n\n\n\n<p>There are some numbers in the comments help explain what every part of the code represents:<\/p>\n\n\n<div class=\"block-core-list\">\n<ol class=\"wp-block-list\">\n<li>The first thing with React components is importing. Here, you import all the other components, functions, constants, etc., needed alongside the rest of the JS file. <em>React<\/em> is the main and default import; it\u2019s necessary to inject React stuff into the current file. <a href=\"https:\/\/reactjs.org\/docs\/react-component.html\">Component<\/a> is one of the possible ways React allows you to represent a component: via class. This way, in point 3, you can extend from the React <code>Component <\/code>element to create a React component by class extension.<\/li>\n\n\n\n<li>Here, you import all the different Reactstrap components you\u2019ll need: from navbar to dropdownmenu. Check their <a href=\"https:\/\/reactstrap.github.io\/components\/alerts\/\">official list of possible components<\/a>.<\/li>\n\n\n\n<li>Creating a new component called <em>AppHeader<\/em>.<\/li>\n\n\n\n<li>When using the class-based component model, React allows you to have a direct <code>state<\/code> variable, which can be defined right after the class declaration, and will store all the properties that are important for the functioning of the current component and just for it. Here, you\u2019re creating a boolean prop called <code>isOpen<\/code> that\u2019ll store the current state of the <code>dropdownmenu<\/code> (that\u2019ll be created soon).<\/li>\n\n\n\n<li>Here, you merely bind the current component to the <code>toggle()<\/code> function below.<\/li>\n\n\n\n<li>The <code>toggle()<\/code> function: it\u2019ll alter the state of the component every time is called, i.e., every time the Reactstrap component orchestrate a call to it to manage if the dropdown is open or not.<\/li>\n\n\n\n<li>The <code>render()<\/code> function: it\u2019s the most important overwritten function of every React component because it is responsible for returning the <a href=\"https:\/\/reactjs.org\/docs\/introducing-jsx.html\">JSX<\/a> code (JSX is a syntax extension to JS, is similar to a template language, but with JavaScript) that visually and functionally represents the component itself. Take a closer look at the code. It\u2019s like a mix of HTML with some tags that were imported earlier from Reactstrap. They are organized in such way that needs to be correctly nested and receive the proper properties. Like in the case of <code>&lt;NavbarToggler><\/code> and <code>&lt;Collapse><\/code> components which rely on both the <code>toggle<\/code> function and <code>isOpen<\/code> property respectively, and previously set. The first determines which function must be called for every click on the toggle icon of the navbar, and the second gets the boolean state value that it\u2019ll use to apply the correct style for open\/closed states. Normal HTML tags are also present, but they are also JSX-like components. For example, notice the declaration of the class name of the <code>&lt;img><\/code> component: <code>className<\/code>. This is JSX.<\/li>\n\n\n\n<li>Lastly, you must export the component. The name here doesn\u2019t need to be the same as your class, but it\u2019s the one you\u2019ll use when importing your component outside of this class.<\/li>\n<\/ol>\n<\/div>\n\n\n<p>It\u2019s also important to remember that React will make sure to recall the <code>render()<\/code> function every time the <code>state<\/code> is changed.<\/p>\n\n\n\n<p>Listing 7 shows the footer component code.<\/p>\n\n\n\n<p class=\"caption\">Listing 7. Second React component: AppFooter.js<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import React, { Fragment } from 'react';\nclass AppFooter extends React.Component {\n    render() {\n        return &lt;Fragment&gt;\n            &lt;hr className=\"featurette-divider\" \/&gt;\n            &lt;footer style={{ padding: \"0 50px\" }} className=\"navbar fixed-bottom\"&gt;\n                &lt;p className=\"float-right\"&gt;&lt;a href=\"\/\"&gt;Back to the Top&lt;\/a&gt;&lt;\/p&gt;\n                &lt;p&gt;\u00a9 2019 Simple-Talk, Inc. \u00b7 &lt;a href=\"\/\"&gt;Term and Conditions&lt;\/a&gt;&lt;\/p&gt;\n            &lt;\/footer&gt;\n        &lt;\/Fragment&gt;;\n    }\n}\nexport default AppFooter;<\/pre>\n\n\n\n<p>This one is simpler. It doesn\u2019t make use of any state manipulation nor JavaScript functions. It\u2019s basically HTML and inline style via JSX syntax. However, notice that you\u2019re importing a new React element: <code>Fragment<\/code>. This is an important shortcut for encapsulating coding in React. In other words, the <code>render()<\/code> function expects to receive a root element that encloses all the other inner elements; otherwise you\u2019ll see a syntax error. In other times, you\u2019d need to use a <code>&lt;div&gt;<\/code> boilerplate tag to do this, but not anymore. <code>&lt;Fragment&gt;<\/code> will do the job without having to insert useless HTML tags into the page.<\/p>\n\n\n\n<p>Before running the example, you need to change the <em>index.js<\/em> and <em>App.js<\/em> files. For instance, every React application starts by a single <em>index.js<\/em> file placed at the root of the app that\u2019ll make some initial configs and call the hierarchy of mounted components. Have a look at the final <em>index.js<\/em> content at Listing 8.<\/p>\n\n\n\n<p class=\"caption\">Listing 8. index.js file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import React from 'react';\nimport ReactDOM from 'react-dom';\nimport '.\/index.css';\nimport 'bootstrap\/dist\/css\/bootstrap.min.css';\nimport App from '.\/App';\nimport * as serviceWorker from '.\/serviceWorker';\nReactDOM.render(&lt;App \/&gt;, document.getElementById('root'));\n\/\/ If you want your app to work offline and load faster, you can change\n\/\/ unregister() to register() below. Note this comes with some pitfalls.\n\/\/ Learn more about service workers: https:\/\/bit.ly\/CRA-PWA\nserviceWorker.unregister();<\/pre>\n\n\n\n<p>Notice that React also makes a call to its <code>render()<\/code> function, passing the root element of the whole application, in this case, <code>&lt;App&gt;<\/code>. But who\u2019s App? Precisely, the <em>App.js<\/em> that is also already preset into the <em>src<\/em> folder (its code is in Listing 9 below). Finally, observe the import of the <em>bootstrap.mim.css<\/em> to make sure the styling will be correctly applied.<\/p>\n\n\n\n<p class=\"caption\">Listing 9. App.js content.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import React, { Component, Fragment } from 'react';\nimport AppHeader from '.\/components\/AppHeader';\nimport AppFooter from '.\/components\/AppFooter';\nclass App extends Component {\n  render() {\n    return &lt;Fragment&gt;\n      &lt;AppHeader \/&gt;\n      &lt;AppFooter \/&gt;\n    &lt;\/Fragment&gt;;\n  }\n}\nexport default App;<\/pre>\n\n\n\n<p><code>App<\/code> components import the two previously implemented components and mount them into another <code>Fragment<\/code>. And that\u2019s it. Issue the <code>npm start<\/code> command again and see what happens to your view (Figure 4).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1257\" height=\"812\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/08\/word-image-87.png\" alt=\"\" class=\"wp-image-85128\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"caption\">Figure 4. Home page with Reactstrap header and footer.<\/p>\n\n\n\n<p>Now, it\u2019s time to get started with the body page content. However, instead of going directly to the table implementation or the fetching the data from the back-end, you\u2019ll begin with the modal component that\u2019ll be responsible for getting the form data information from the user, just like shown in Figure 5.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"655\" height=\"624\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/08\/word-image-88.png\" alt=\"\" class=\"wp-image-85129\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"caption\">Figure 5. Modal with form data.<\/p>\n\n\n\n<p>Why this? This is a bottom-up strategy to help you understand the details from a more fine-grained perspective.<\/p>\n\n\n\n<p>For instance, the same form will be used for both adding and editing information of a user. That\u2019ll simplify the code and allow reuse of components. Before diving in, create a new folder <em>\/constants<\/em> at the same level of <em>\/components<\/em> folder. Inside of it, create an <em>index.js<\/em> file and place the following content into it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">export const USERS_API_URL = 'https:\/\/localhost:5001\/api\/users';<\/pre>\n\n\n\n<p>This will be the constant of the API address. Then, create a new folder into <em>\/components<\/em> called <em>\/form<\/em>, to store the components related to form manipulation. Inside, create two new files: <em>RegistrationForm.js<\/em> and <em>RegistrationModal.js<\/em>. Listing 10 shows the code for the first one.<\/p>\n\n\n\n<p class=\"caption\">Listing 10. Creating the RegistrationForm.js file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import React from 'react';\nimport { Button, Form, FormGroup, Input, Label } from 'reactstrap';\nimport { USERS_API_URL } from '..\/..\/constants';\nclass RegistrationForm extends React.Component {\n    state = {\n        id: 0,\n        name: '',\n        document: '',\n        email: '',\n        phone: ''\n    }\n    componentDidMount() {\n        if (this.props.user) {\n            const { id, name, document, email, phone } = this.props.user\n            this.setState({ id, name, document, email, phone});\n        }\n    }\n    onChange = e =&gt; {\n        this.setState({ [e.target.name]: e.target.value })\n    }\n    submitNew = e =&gt; {\n        e.preventDefault();\n        fetch(`${USERS_API_URL}`, {\n            method: 'post',\n            headers: {\n                'Content-Type': 'application\/json'\n            },\n            body: JSON.stringify({\n                name: this.state.name,\n                document: this.state.document,\n                email: this.state.email,\n                phone: this.state.phone\n            })\n        })\n            .then(res =&gt; res.json())\n            .then(user =&gt; {\n                this.props.addUserToState(user);\n                this.props.toggle();\n            })\n            .catch(err =&gt; console.log(err));\n    }\n    submitEdit = e =&gt; {\n        e.preventDefault();\n        fetch(`${USERS_API_URL}\/${this.state.id}`, {\n            method: 'put',\n            headers: {\n                'Content-Type': 'application\/json'\n            },\n            body: JSON.stringify({\n                name: this.state.name,\n                document: this.state.document,\n                email: this.state.email,\n                phone: this.state.phone\n            })\n        })\n            .then(() =&gt; {\n                this.props.toggle();\n                this.props.updateUserIntoState(this.state.id);\n            })\n            .catch(err =&gt; console.log(err));\n    }\n    render() {\n        return &lt;Form onSubmit={this.props.user ? this.submitEdit : this.submitNew}&gt;\n            &lt;FormGroup&gt;\n                &lt;Label for=\"name\"&gt;Name:&lt;\/Label&gt;\n                &lt;Input type=\"text\" name=\"name\" onChange={this.onChange} value={this.state.name === '' ? '' : this.state.name} \/&gt;\n            &lt;\/FormGroup&gt;\n            &lt;FormGroup&gt;\n                &lt;Label for=\"document\"&gt;Document:&lt;\/Label&gt;\n                &lt;Input type=\"text\" name=\"document\" onChange={this.onChange} value={this.state.document === null ? '' : this.state.document} \/&gt;\n            &lt;\/FormGroup&gt;\n            &lt;FormGroup&gt;\n                &lt;Label for=\"email\"&gt;Email:&lt;\/Label&gt;\n                &lt;Input type=\"email\" name=\"email\" onChange={this.onChange} value={this.state.email === null ? '' : this.state.email} \/&gt;\n            &lt;\/FormGroup&gt;\n            &lt;FormGroup&gt;\n                &lt;Label for=\"phone\"&gt;Phone:&lt;\/Label&gt;\n                &lt;Input type=\"text\" name=\"phone\" onChange={this.onChange} value={this.state.phone === null ? '' : this.state.phone}\n                    placeholder=\"+1 999-999-9999\" \/&gt;\n            &lt;\/FormGroup&gt;\n            &lt;Button&gt;Send&lt;\/Button&gt;\n        &lt;\/Form&gt;;\n    }\n}\nexport default RegistrationForm;<\/pre>\n\n\n\n<p>First, consider the React imports. Here, you\u2019re making use of Reactstrap form components. Then, comes the state definition: just single properties representing each one of the inputs in the user registration form.<\/p>\n\n\n\n<p>The function <a href=\"https:\/\/reactjs.org\/docs\/react-component.html#componentdidmount\">componentDidMount()<\/a> is new: it is invoked immediately after a component is mounted (inserted into the tree), which is good because the user props will be passed down to this component as <a href=\"https:\/\/reactjs.org\/docs\/components-and-props.html\">a property<\/a> (available through <code>this.props<\/code> snippet). The props are like params of a function in JavaScript, but in this case, as params from one component to another. The code is checking for its existence, which will mean that it\u2019s an editing action; otherwise consider it just a new registration. If the user is present, extract its props and set them to the current state. You may already guess why. Yes, it\u2019s because they need to fill the inputs before the modal opens.<\/p>\n\n\n\n<p>The <code>onChange()<\/code> function is a simple function to receive an <code>onChange <\/code>event and change the component state accordingly.<\/p>\n\n\n\n<p>The <code>submitNew()<\/code> function will handle the <code>onSubmit<\/code> event, specifically on calling the API to submit a new user. Notice the reliance on the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Fetch_API\">Fetch API<\/a> to make the HTTP calls, but feel free to use whichever library in which you feel comfortable. The function code is very intuitive by itself. Notice that at the end, it gets the json response data and sends it to the function <code>addUserToState()<\/code> (which is not implemented in this component, since this comes within the <code>props<\/code> object). The <code>toggle()<\/code> is another function implemented later, so don\u2019t worry about it now.<\/p>\n\n\n\n<p>The <code>submitEdit()<\/code> function will do practically the exact same things as <code>submitNew()<\/code>, except for the API endpoint and the response dealing function, this time <code>updateUserIntoState()<\/code>.<\/p>\n\n\n\n<p>Finally, the render function is prepared to identify whether the user comes within the props or not and places the correct submit function to the <code>&lt;Form&gt;<\/code> component. Based on this, if the <code>state<\/code> of the component was previously set with the user\u2019s info, then the value of each input will be filled correspondently.<\/p>\n\n\n\n<p>Great! Next stop is the <code>RegistrationModal<\/code> component which will import the form and hold the rules for its exhibition. Look at the Listing 11 for its code.<\/p>\n\n\n\n<p class=\"caption\">Listing 11. Creating the RegistrationModal.js file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import React, { Component, Fragment } from 'react';\nimport { Button, Modal, ModalHeader, ModalBody } from 'reactstrap';\nimport RegistrationForm from '.\/RegistrationForm';\nclass RegistrationModal extends Component {\n    state = {\n        modal: false\n    }\n    toggle = () =&gt; {\n        this.setState(previous =&gt; ({\n            modal: !previous.modal\n        }));\n    }\n    render() {\n        const isNew = this.props.isNew;\n        let title = 'Edit User';\n        let button = '';\n        if (isNew) {\n            title = 'Add User';\n            button = &lt;Button\n                color=\"success\"\n                onClick={this.toggle}\n                style={{ minWidth: \"200px\" }}&gt;Add&lt;\/Button&gt;;\n        } else {\n            button = &lt;Button\n                color=\"warning\"\n                onClick={this.toggle}&gt;Edit&lt;\/Button&gt;;\n        }\n        return &lt;Fragment&gt;\n            {button}\n            &lt;Modal isOpen={this.state.modal} toggle={this.toggle} className={this.props.className}&gt;\n                &lt;ModalHeader toggle={this.toggle}&gt;{title}&lt;\/ModalHeader&gt;\n                &lt;ModalBody&gt;\n                    &lt;RegistrationForm\n                        addUserToState={this.props.addUserToState}\n                        updateUserIntoState={this.props.updateUserIntoState}\n                        toggle={this.toggle}\n                        user={this.props.user} \/&gt;\n                &lt;\/ModalBody&gt;\n            &lt;\/Modal&gt;\n        &lt;\/Fragment&gt;;\n    }\n}\nexport default RegistrationModal;<\/pre>\n\n\n\n<p>Way more straightforward than the form component, this one has its own <code>toggle()<\/code> function (the one called in the previous listing) to be passed as a <code>props<\/code> function. It simply toggles the state of the boolean <code>modal<\/code> state attribute every time an HTTP call is finished in order to close the modal automatically.<\/p>\n\n\n\n<p>Here, you\u2019re also receiving values via <code>props<\/code> from the outer components that call it. In this case, <code>isNew<\/code> will tell if the user is a new one or an existing one, which is essential information for determining which form state will be presented. Also, you can use this info to change the labels of the button, for example. It can be either an <em>Add<\/em> or <em>Edit<\/em> labeled button. Notice how you\u2019re also applying the class of the modal based on another property passed via <em>props<\/em>. The rest of the code is just filling the blanks of each property needed by a <code>RegistrationModal<\/code>.<\/p>\n\n\n\n<p>This is good until now, but you need to move forward to the next two components that\u2019ll close the implementation: <em>DataTable.js<\/em> and <em>Home.js<\/em>. The <em>DataTable<\/em> component, as you may guess, is the one who\u2019s going to store the table with the list of users fetched from the back-end.<\/p>\n\n\n\n<p class=\"caption\">Listing 12. Creating the DataTable.js file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import React, { Component } from 'react';\nimport { Table, Button } from 'reactstrap';\nimport RegistrationModal from '.\/form\/RegistrationModal';\nimport { USERS_API_URL } from '..\/constants';\nclass DataTable extends Component {\n  deleteItem = id =&gt; {\n    let confirmDeletion = window.confirm('Do you really wish to delete it?');\n    if (confirmDeletion) {\n      fetch(`${USERS_API_URL}\/${id}`, {\n        method: 'delete',\n        headers: {\n          'Content-Type': 'application\/json'\n        }\n      })\n        .then(res =&gt; {\n          this.props.deleteItemFromState(id);\n        })\n        .catch(err =&gt; console.log(err));\n    }\n  }\n  render() {\n    const items = this.props.items;\n    return &lt;Table striped&gt;\n      &lt;thead className=\"thead-dark\"&gt;\n        &lt;tr&gt;\n          &lt;th&gt;Id&lt;\/th&gt;\n          &lt;th&gt;Name&lt;\/th&gt;\n          &lt;th&gt;Email&lt;\/th&gt;\n          &lt;th&gt;Document&lt;\/th&gt;\n          &lt;th&gt;Phone&lt;\/th&gt;\n          &lt;th style={{ textAlign: \"center\" }}&gt;Actions&lt;\/th&gt;\n        &lt;\/tr&gt;\n      &lt;\/thead&gt;\n      &lt;tbody&gt;\n        {!items || items.length &lt;= 0 ?\n          &lt;tr&gt;\n            &lt;td colSpan=\"6\" align=\"center\"&gt;&lt;b&gt;No Users yet&lt;\/b&gt;&lt;\/td&gt;\n          &lt;\/tr&gt;\n          : items.map(item =&gt; (\n            &lt;tr key={item.id}&gt;\n              &lt;th scope=\"row\"&gt;\n                {item.id}\n              &lt;\/th&gt;\n              &lt;td&gt;\n                {item.name}\n              &lt;\/td&gt;\n              &lt;td&gt;\n                {item.email}\n              &lt;\/td&gt;\n              &lt;td&gt;\n                {item.document}\n              &lt;\/td&gt;\n              &lt;td&gt;\n                {item.phone}\n              &lt;\/td&gt;\n              &lt;td align=\"center\"&gt;\n                &lt;div&gt;\n                  &lt;RegistrationModal\n                    isNew={false}\n                    user={item}\n                    updateUserIntoState={this.props.updateState} \/&gt;\n                  &amp;nbsp;&amp;nbsp;&amp;nbsp;\n                  &lt;Button color=\"danger\" onClick={() =&gt; this.deleteItem(item.id)}&gt;Delete&lt;\/Button&gt;\n                &lt;\/div&gt;\n              &lt;\/td&gt;\n            &lt;\/tr&gt;\n          ))}\n      &lt;\/tbody&gt;\n    &lt;\/Table&gt;;\n  }\n}\nexport default DataTable;<\/pre>\n\n\n\n<p>The first function of the component is the <code>deleteItem()<\/code>, which will perform an HTTP call for deleting a user. The id is received as a param, and the function <code>deleteItemFromState()<\/code> (shown later) will be called as soon as the request completes.<\/p>\n\n\n\n<p>Note that the render function is receiving a prop called <code>items<\/code> from the outer component with the list of users to iterate and show into the table. For the <code>&lt;tbody&gt;<\/code>, it first checks for the absence of any item into the list and then shows a corresponding message of \u201cNo Users yet\u201d, otherwise, the list will be iterated and, at the <code>Actions<\/code> column, each item will have a <code>&lt;RegistrationModal&gt;<\/code> imported along with a button for items deletion.<\/p>\n\n\n\n<p>Pay attention to how React makes use of its componentization style to make it simple to reuse components and reference them from the others.<\/p>\n\n\n\n<p>Listing 13 shows the code of the Home.js component.<\/p>\n\n\n\n<p class=\"caption\">Listing 13. Creating the Home.js file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import React, { Component } from 'react';\nimport { Col, Container, Row } from 'reactstrap';\nimport DataTable from '.\/DataTable';\nimport RegistrationModal from '.\/form\/RegistrationModal';\nimport { USERS_API_URL } from '..\/constants';\nclass Home extends Component {\n  state = {\n    items: []\n  }\n  componentDidMount() {\n    this.getItens();\n  }\n  getItens = () =&gt; {\n    fetch(USERS_API_URL)\n      .then(res =&gt; res.json())\n      .then(res =&gt; this.setState({ items: res }))\n      .catch(err =&gt; console.log(err));\n  }\n  addUserToState = user =&gt; {\n    this.setState(previous =&gt; ({\n      items: [...previous.items, user]\n    }));\n  }\n  updateState = (id) =&gt; {\n    this.getItens();\n  }\n  deleteItemFromState = id =&gt; {\n    const updated = this.state.items.filter(item =&gt; item.id !== id);\n    this.setState({ items: updated })\n  }\n  render() {\n    return &lt;Container style={{ paddingTop: \"100px\" }}&gt;\n      &lt;Row&gt;\n        &lt;Col&gt;\n          &lt;h3&gt;My First React + ASP.NET CRUD React&lt;\/h3&gt;\n        &lt;\/Col&gt;\n      &lt;\/Row&gt;\n      &lt;Row&gt;\n        &lt;Col&gt;\n          &lt;DataTable\n            items={this.state.items}\n            updateState={this.updateState}\n            deleteItemFromState={this.deleteItemFromState} \/&gt;\n        &lt;\/Col&gt;\n      &lt;\/Row&gt;\n      &lt;Row&gt;\n        &lt;Col&gt;\n          &lt;RegistrationModal isNew={true} addUserToState={this.addUserToState} \/&gt;\n        &lt;\/Col&gt;\n      &lt;\/Row&gt;\n    &lt;\/Container&gt;;\n  }\n}\nexport default Home;<\/pre>\n\n\n\n<p>Here are some assumptions to analyze:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li>The state will have an array of items (the users) to manipulate throughout the app use;<\/li>\n\n\n\n<li>Once the component mounts, it fetches the list of users from the API (<code>getItens<\/code> function);<\/li>\n\n\n\n<li>The <code>getItens()<\/code> function will make a GET request, convert the response to json, set it to the current state, or log any error if it happens;<\/li>\n\n\n\n<li>The <code>addUserToState() <\/code>function (which you\u2019ve seen called before) will receive a user and add it to the current state;<\/li>\n\n\n\n<li>The <code>updateState()<\/code> function will also fetch the items from the server, but note that it\u2019s receiving the id as a param, that you can use to update it just into the state list, if you want;<\/li>\n\n\n\n<li>The <code>deleteItemFromState()<\/code> function will receive the id to perform the user\u2019s corresponding deletion from the current state;<\/li>\n\n\n\n<li>The <code>render()<\/code> function is just a summary of a simple JSX content for building the <code>&lt;DataTable><\/code> and <code>&lt;RegistrationModal><\/code> components into Bootstrap row\/column structures.<\/li>\n<\/ul>\n<\/div>\n\n\n<p>You still need to add the <code>&lt;Home&gt;<\/code> component to the main one, <code>&lt;App&gt;<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">  render() {\n    return &lt;Fragment&gt;\n      &lt;AppHeader \/&gt;\n      &lt;Home \/&gt;\n      &lt;AppFooter \/&gt;\n    &lt;\/Fragment&gt;;\n  }<\/pre>\n\n\n\n<p>Finally, don\u2019t forget to import the new <code>Home<\/code> component at the top of the file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import Home from '.\/components\/Home';<\/pre>\n\n\n\n<p>Once the application is refreshed in the browser, and if the API is not running, this is the screen you\u2019ll see:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1470\" height=\"336\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/08\/word-image-89.png\" alt=\"\" class=\"wp-image-85130\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"caption\">Figure 6. Table of users with no entries.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p><a id=\"post-85124-_heading=h.gjdgxs\"><\/a> That\u2019s it. Go ahead, run the API and test the interface it by yourself, making sure to verify if Reacstrap made it responsive for you as well.<\/p>\n\n\n\n<p>This was just a brief intro around the universe of React and how you can connect it, not only with ASP.NET based APIs, but with any type of API. Some details, like the Cors configs, are essential to make sure they can communicate with each other.<\/p>\n\n\n\n<p>You can also check the full source code <a href=\"https:\/\/github.com\/iamjuliosampaio\/ReactASPNET\">here<\/a>. Good studies!<\/p>\n\n\n\n<section id=\"faq\" class=\"faq-block my-5xl\">\n    <h2>FAQs: Creating ASP.NET Apps with React<\/h2>\n\n                        <h3 class=\"mt-4xl\">1. How do I connect a React frontend to an ASP.NET Core Web API?<\/h3>\n            <div class=\"faq-answer\">\n                <p>Run both projects separately &#8211; the ASP.NET Core API on one port (e.g., 5001) and the React app on another (e.g., 3000). In the React app, configure the API base URL and use fetch() or axios to call the API endpoints. In the ASP.NET Core API, configure CORS in Program.cs to allow requests from the React dev server origin: builder.Services.AddCors(options =&gt; options.AddPolicy(&#8220;ReactPolicy&#8221;, p =&gt; p.WithOrigins(&#8220;http:\/\/localhost:3000&#8221;).AllowAnyMethod().AllowAnyHeader())). For production, serve the React build output as static files from the ASP.NET Core app.<\/p>\n            <\/div>\n                    <h3 class=\"mt-4xl\">2. What is Reactstrap and why use it with ASP.NET Core React apps?<\/h3>\n            <div class=\"faq-answer\">\n                <p>Reactstrap provides React components that wrap Bootstrap 4 CSS classes &#8211; giving you pre-built, responsive UI components (Navbar, Card, Button, Form, etc.) that work as React components rather than raw HTML with class names. For ASP.NET Core apps transitioning from Razor\/Bootstrap, Reactstrap provides a familiar Bootstrap look and feel in React. Install via npm: npm install reactstrap bootstrap. Import Bootstrap CSS in index.js: import &#8216;bootstrap\/dist\/css\/bootstrap.min.css&#8217;.<\/p>\n            <\/div>\n                    <h3 class=\"mt-4xl\">3. Should I use the ASP.NET Core React template or set up manually?<\/h3>\n            <div class=\"faq-answer\">\n                <p>Visual Studio and the .NET CLI provide an ASP.NET Core with React template (dotnet new react) that scaffolds both projects in a single solution with a pre-configured proxy. This is faster for new projects. The manual approach (separate API project + Create React App) gives more control over tooling versions and project structure &#8211; preferable when you need specific React versions or want to keep front-end and back-end in separate repositories. The article demonstrates the manual approach for full transparency about what each part does.<\/p>\n            <\/div>\n                    <h3 class=\"mt-4xl\">4. How do I handle CORS errors between an ASP.NET Core API and React?<\/h3>\n            <div class=\"faq-answer\">\n                <p>CORS errors occur in development when the React app (e.g., localhost:3000) calls the API (e.g., localhost:5001) because they are on different origins. Fix in ASP.NET Core: add CORS middleware with a permissive development policy using builder.Services.AddCors(), define a policy allowing your React origin, and add app.UseCors(&#8220;PolicyName&#8221;) before app.UseRouting() in the middleware pipeline. In production, restrict the CORS policy to only the deployed front-end domain.<\/p>\n            <\/div>\n            <\/section>\n","protected":false},"excerpt":{"rendered":"<p>Build an ASP.NET Core Web API backend and connect it to a React frontend using Reactstrap. Covers Visual Studio API project setup, Node.js React project creation, component structure, and wiring the two together.&hellip;<\/p>\n","protected":false},"author":323407,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":true,"footnotes":""},"categories":[143538],"tags":[],"coauthors":[93894],"class_list":["post-85124","post","type-post","status-publish","format-standard","hentry","category-dotnet-development"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/85124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/323407"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=85124"}],"version-history":[{"count":8,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/85124\/revisions"}],"predecessor-version":[{"id":109788,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/85124\/revisions\/109788"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=85124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=85124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=85124"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=85124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}