Home
Softono

React Starter

Open source MIT TypeScript
92
Stars
5
Forks
6
Issues
2
Watchers
6 months
Last Commit

 About React Starter

A template capable of server-side rendering, generating static pages, serving single-page applications, and providing an API.

Platforms

Web Self-hosted

Languages

TypeScript

Need Help Installing React Starter?

We provide expert installation service for this software. Our team will install, configure, and secure React Starter on your server. plans start at just $30.

React Starter

View on GitHub

React Starter Kit

A minimal, flexible React template built with Vite supporting multiple rendering modes

✨ Features

  • πŸ”„ Multiple Rendering Modes: SSR, SSG, and SPA support with route-level control
  • πŸš€ File-based API Routes: Build serverless APIs with simple file structure
  • 🎯 Framework-agnostic: Pure React with Vite - no complex abstractions
  • πŸ” SEO Ready: Built-in meta tags and server-side rendering for better SEO
  • πŸ“¦ Universal Deployment: Compatible with Stormkit, Netlify, Vercel and more
  • ⚑ Hot Module Replacement: Instant updates during development
  • 🏷️ TypeScript First: Full TypeScript support out of the box
  • 🎨 Modern Tooling: Vite for lightning-fast builds and development

πŸš€ Quick Start

Installation

# Clone or use as template
git clone <repository-url>
cd react-starter

# Install dependencies
npm install
# or
yarn install
# or
pnpm install

Development

npm run dev

Visit http://localhost:5173 to see your app running with HMR enabled.

πŸ“ Project Structure

src/
β”œβ”€β”€ api/                 # API routes (serverless functions)
β”‚   └── hello.ts        # Example API endpoint
β”œβ”€β”€ pages/              # Application pages
β”‚   β”œβ”€β”€ home.tsx        # Home page (SPA)
β”‚   β”œβ”€β”€ about.tsx       # About page (SPA)
β”‚   └── ssr.tsx         # SSR example with fetchData
β”œβ”€β”€ components/         # Reusable components
β”œβ”€β”€ context.ts          # React context for data sharing
β”œβ”€β”€ entry-client.tsx    # Client-side entry point
β”œβ”€β”€ entry-server.tsx    # Server-side entry point
β”œβ”€β”€ prerender.ts        # SSG route configuration
└── App.tsx            # Main application component

πŸ”§ Build Commands

Development Server

npm run dev

Starts development server with HMR at http://localhost:5173

Single Page Application (SPA)

npm run build:spa

Builds a traditional SPA. Output: .stormkit/public/

Server-Side Rendering (SSR)

npm run build:ssr

Builds for serverless deployment with SSR. Output: .stormkit/server/

Static Site Generation (SSG)

npm run build:spa  # Build SPA first
npm run build:ssg  # Generate static pages

Pre-renders specified routes at build time. Output: .stormkit/public/

API Only

npm run build:api

Builds only the API functions. Output: .stormkit/api/

🎯 Rendering Modes

Single Page Application (Default)

All routes are client-side rendered by default:

// src/pages/home.tsx
export default function Home() {
  return <h1>Welcome to Home</h1>;
}

Server-Side Rendering

Add a fetchData export to enable SSR:

import { useContext } from "react";
import Context from "~/context";

// src/pages/ssr.tsx
export async function fetchData() {
  const data = await fetch("https://api.example.com/data");
  return {
    head: {
        // meta tags
    },
    context: {
        myParam: data.myParam;
    }
  };
}

export default function SSRPage({ data }: { data: any }) {
  const context = useContext(Context);
  return <h1>Server-rendered: {data.myParam}</h1>;
}

Static Site Generation

Configure routes to pre-render in src/prerender.ts:

// src/prerender.ts

// Export an array of paths to be prerendered.
export default ["/", "/about", "/blog/post-1"];

πŸ”Œ API Routes

Create API endpoints by adding files to src/api/:

// src/api/hello.ts
export default async (req: http.IncomingMessage, res: http.ServerResponse) => {
  res.setHeader("Content-Type", "application/json");
  res.writeHead(200, "Success");
  res.write(
    JSON.stringify({
      payload:
        "This is an API function - can be deployed as a serverless function!",
    })
  );
  res.end();
};

Access at: http://localhost:5173/api/hello

πŸš€ Deployment

Stormkit

Import this application on Stormkit (either self-hosted or cloud) and simply click deploy. It works with zero-config.

Static Hosting

npm run build:spa
npm run build:ssg  # Optional: for pre-rendered pages

Deploy the .stormkit/public folder.

πŸ”§ Configuration

Vite Configuration

  • vite.config.ts - Development server
  • vite.config.ssr.ts - SSR build
  • vite.config.spa.ts - SPA build
  • vite.config.api.ts - API build

πŸ› οΈ Advanced Usage

Custom Server

// server.ts
import { handler } from "./.stormkit/server/server.mjs";

const server = express();
server.use(handler);
server.listen(3000);

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

πŸ“š Resources

🌟 Showcase

Websites built with this template:

Site Description Features Used
Stormkit.io Deploy full-stack JavaScript apps SSR, API Routes
Add your site Submit your project -

πŸ“„ License

MIT Β©