C
CanxJS
v1.6.2
  • Learn
  • Blog
  • Showcase
C
CanxJS

Ultra-fast async MVC backend framework for Bun. Build production-ready APIs with elegance and speed.

Resources

  • Documentation
  • Learn
  • Blog
  • Showcase

Documentation

  • Introduction
  • Installation
  • Core Concepts
  • CLI Commands
  • API Reference

Legal

  • Privacy Policy
  • Terms of Service

© 2026 CanxJS. All rights reserved.

Built with ❤️ for Candra Kirana

  • Vite Integration
  • Inertia.js
  • HotWire Protocol
  • Views (JSX)
Frontend

Views (JSX)

Build server-rendered user interfaces using JSX components. No comprehensive frontend framework required.

JSX Support

Write views using familiar JSX syntax.

Layouts

Create reusable layouts for your pages.

SSR

Server-side rendering for better SEO.

Fast

Powered by Bun's native JSX transpiler.

Creating Views

Views are just functions that return JSX. Save them in `src/views`.

src/views/welcome.tsx
1// src/views/welcome.tsx
2export default function Welcome({ name }: { name: string }) {
3 return (
4 <div className="p-10">
5 <h1>Hello, {name}!</h1>
6 <p>Welcome to CanxJS</p>
7 </div>
8 );
9}

Rendering Views

Use the `view()` helper in your controllers.

home.controller.ts
1import { Controller, Get, view } from "canxjs";
2
3@Controller()
4export class HomeController {
5
6 @Get()
7 async index() {
8 // Renders src/views/welcome.tsx
9 return await view('welcome', { name: 'World' });
10 }
11}

Layouts

src/views/layouts/main.tsx
1import { createLayout } from "canxjs";
2
3const MainLayout = ({ children, title }) => (
4 <html>
5 <head><title>{title}</title></head>
6 <body>{children}</body>
7 </html>
8);
9
10// Usage
11export default createLayout(MainLayout);

Client-Side Interactivity

⚠️ Important Note on Hooks

CanxJS views are server-rendered only. This means standard React hooks likeuseState, useEffect, or event handlers like onClick inside your JSX will not work and may cause errors.

For client-side interactivity, we recommend using modern, lightweight libraries that work great with server-rendered HTML, such as Alpine.js or vanilla JavaScript script tags.

interactive-component.tsx
1// src/views/counter.tsx
2export default function Counter() {
3 return (
4 <div x-data="{ count: 0 }" className="p-4">
5 <span x-text="count" className="text-xl font-bold"></span>
6 <button
7 @click="count++"
8 className="ml-4 px-4 py-2 bg-blue-500 rounded"
9 >
10 Increment
11 </button>
12
13 {/* Alternatives */}
14 <section className="mb-16">
15 <h2 className="text-2xl font-semibold text-foreground mb-4">Alternative View Engines</h2>
16 <div className="rounded-2xl bg-card border border-border p-6 space-y-4">
17 <p className="text-muted-foreground leading-relaxed">
18 CanxJS uses <strong>JSX/TSX</strong> as its native first-class view engine because it provides the best performance (compiled directly by Bun) and developer experience (full type safety).
19 </p>
20 <p className="text-muted-foreground leading-relaxed">
21 <strong>Can I use other engines like EJS or Handlebars?</strong><br />
22 Yes! While JSX is the default, CanxJS is just JavaScript. You can install any template engine (like <code className="text-primary">ejs</code> or <code className="text-primary">handlebars</code>) from npm and use it in your controllers, just like you would in Express. However, you will miss out on the performance benefits of the native JSX renderer.
23 </p>
24 </div>
25 </section>
26
27 {/* Next Steps */}
28 <script src="//unpkg.com/alpinejs" defer></script>
29 </div>
30 );
31}