I am trying to figure out how I can get an ApiUrl setting from my AppSettings.json into my ReactJS / Redux state.
I have found the following article, however, it is for Angular. https://elanderson.net/2017/10/pass-asp-net-core-appsettings-values-to-angular/
I was able to use the example to alter my MVC page to this:
@using Microsoft.Extensions.Configuration @inject IConfiguration Configuration @{ ViewData["Title"] = "Home Page"; }
<div id="react-app" asp-prerender-module="ClientApp/dist/main-server" asp-prerender-data='new { apiUrl = Configuration["ApiUrl"] }'>Loading...</div>
@section scripts {
<script src="~/dist/main-client.js" asp-append-version="true"></script>
}
Here is my AppSettings.json:
{
"ApiUrl": "http://localhost:55556/",
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
I want to send the ApiUrl parameter from my AppSettings to the ApplicationState and access it from my ReactJS TypeScript components.
I created this app with the command dotnet new reactredux
and I am very new to ReactJS and Redux.