Create React App integration with ReactJS.net

162 Views Asked by At

I'm trying to set up a asp.net mvc project integrating a create react app and reactjs.net. Trying to follow the tutorial here but facing this exception

ReactJS.NET has not been initialised correctly. Please ensure you have called services.AddReact() and app.UseReact() in your Startup.cs file. (ReactNotInitialisedException)
ReactNotInitialisedException at React.ReactEnvironment.get_GetCurrentOrThrow()
    No JS engines were registered. Visit https://reactjs.net/docs for more information. (ReactException)

This is my ReactConfig file. I have tried some combinations here to not load react and set JS engines.

ReactSiteConfiguration.Configuration
              .SetLoadBabel(false)
              .SetLoadReact(false)
              .SetReactAppBuildPath("~/ClientApp/build");
JsEngineSwitcher.Current.DefaultEngineName = V8JsEngine.EngineName;
            JsEngineSwitcher.Current.EngineFactories.AddV8();

This is my layout cshtml.

<html>
<head>
    <title>Hello React</title>
    <link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
</head>
<body className="">
    <div id="content"></div>
    @Html.React("Components.App", new{p1 = "value"})
</body>
</html>

From the tutorial, instead of expose-components.js, I'm doing the same in my default index.js as this would be the default entry point for the create react app and I did not want to eject it. I do not have a startup.cs file in my MVC project instead have a Global.ascx.cs

0

There are 0 best solutions below