Swap.Htmx vs React

Two fundamentally different approaches to building web applications.

React is a client-side JavaScript library for building SPAs. It renders UI in the browser and manages state on the client.

Swap.Htmx is a server-driven approach. HTML is rendered on the server, and HTMX handles partial page updates via HTTP.

Aspect⚛️ React🔄 Swap.Htmx
ArchitectureSingle Page Application (SPA)Server-driven partials
LanguageJavaScript/TypeScript + JSXC# + Razor (HTML)
Bundle Size100kb+ minimum~14kb (HTMX only)
State ManagementClient-side (useState, Redux)Server-side (SwapState)
SEOPoor by default (needs SSR)Excellent
Learning CurveMedium-HighLow
ToolingNode.js, npm, webpack/vite.NET SDK only

When to Choose React

  • ✓ Highly interactive apps (real-time collaboration)
  • ✓ Offline-first applications
  • ✓ Rich animations and transitions
  • ✓ Team already knows React
  • ✓ Need React ecosystem libraries

When to Choose Swap.Htmx

  • ✓ Content-heavy sites, dashboards, CRUD
  • ✓ SEO is important
  • ✓ .NET team wants to stay in C#
  • ✓ Simpler deployment
  • ✓ Faster initial page loads

Code Comparison

React + API

const [todos, setTodos] = useState([]);
useEffect(() => {
  fetch('/api/todos')
    .then(r => r.json())
    .then(setTodos);
}, []);
// + deleteTodo, loading, error...

Swap.Htmx

public IActionResult TodoList()
    => SwapView(_db.Todos.ToList());
public IActionResult Delete(int id) {
    _db.Remove(_db.Find(id));
    return SwapResponse().Remove($"#todo-{id}");
}