Skip to content

Repository files navigation

JsxCore: JSX and React, natively in ASP.NET Core

JsxCore

A TSX/JSX view engine for ASP.NET Core.

Build NuGet License: MIT

Native JSX, React, Preact and TypeScript support for ASP.NET MVC, WebAPI and Minimal APIs. JsxCore provides a "vite-like" developer experience to the .NET ecosystem.

This makes ASP.NET Core a fully featured React and TypeScript developer experience, comparable and competitive with Node-based frameworks like Next.js, Remix, and Astro, but without the Node runtime or npm dependency.

The developer experience

Sold already? Go get started or install the package.

Comprehensive Documentation

Want to know more?

Write your views as .tsx files and return them from a controller or a minimal API. They are real components — real JSX, rendered by Preact, which ships inside the package, or by React, which the build restores for you — running on the server for first paint, in the browser for interactivity, or both, chosen per response. The model comes from your endpoint, and its TypeScript type is generated from your C#, so the two cannot drift.

Key Features:

  • Use React or Preact as ASP.NET Core Views
  • Zero configuration: the package handles sourcing TypeScript compilers and esbuild minifiers automatically, so there is no setup step to forget.
  • Views are components. The same component renders on the server for first paint and SEO, in the browser for interactivity, or both, chosen per response.
  • No bundler. TypeScript rewrites ./Card.tsx to ./Card.js, so the browser resolves the module graph itself.
  • Real .NET interop. Server rendering runs in-process, so .NET objects exposed to a view are real objects, called synchronously with no bridge.
  • npm packages work. Install a package and import it; it resolves on the server and is served to the browser, with no bundler and no import map to write. dotnet npm add marked installs one without npm on the machine.
  • Idiomatic .NET Preact ships inside the package, so nothing is installed to render a view. One project-file property switches to React, which the build restores for you.
  • Types generated from your C#. View models are described once, in .NET.
  • Drops into MVC. Registers as an IViewEngine, so return View() finds Index.tsx.

Install

dotnet add package JsxCore

The .NET SDK is the only prerequisite.

JsxCore restores the npm packages it needs itself, by talking to the registry directly, so a clean checkout builds with dotnet build on a machine with no Node and no npm installed.

Prerequisites: .NET 8, 9 or 10. Views that import npm packages still need those package files on the server, which publish will copy for you.


Quick start: minimal API

using JsxCore.Hosting;
using JsxCore.Mvc;

var builder = WebApplication.CreateBuilder(args);
builder.AddJsxCore();

var app = builder.Build();
app.UseJsxCore();

app.MapGet("/", () => Results.Extensions.Jsx("Home/Index", new { name = "World" }));

app.Run();
// Views/Home/Index.tsx
export default function Index({ model }: { model: { name: string } }) {
    return <h1>Hello {model.name}</h1>;
}

Run the app.


Sample apps included

samples/SampleApp demonstrates every render mode, .NET globals, MVC integration, generated model types and Preact features:

dotnet run --project samples/SampleApp

You'll see a view mounted in the browser, from a model serialised by your endpoint:

A client-rendered JsxCore view, with a working counter

Calling .NET from a server-rendered view. No fetch, no API, no bridge: the component asked a C# service for the total during rendering, and the browser received markup:

A server-rendered view reading values from a .NET service

A type error while you work. The watcher recompiles on save and pushes the diagnostics to the page, rather than serving a stale build or a blank screen:

The development overlay showing a TypeScript compilation error

Licence

MIT. See LICENSE.

About

Native support for JSX and TSX as a server and client rendered view engine for ASP.NET Core. Bringing the modern web to ASP.NET.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages