react-ts-template Tailwind Templates

React Ts Template

This React TypeScript template, built with Vite, provides a solid foundation for your web application with integrated libraries like React Query, Zustand, and Tailwind CSS.

πŸš€ React TypeScript Template - Your Next Web App Starts Here!

δΈ­ζ–‡ README

This repository is a carefully configured React TypeScript template designed to help you quickly start developing new web applications. It integrates modern front-end development best practices and commonly used tools, allowing you to focus on building excellent user interfaces and experiences without configuring the basic infrastructure from scratch.

✨ Key Features

  • ⚑️ Blazing Fast Development Experience: Built with Vite, providing lightning-fast cold starts and Hot Module Replacement (HMR).
  • πŸ›‘οΈ Type Safety: Using TypeScript to provide static type checking, reduce runtime errors, and improve code maintainability.
  • βš›οΈ Component-Based Architecture: Clear directory structure encouraging component-based development for better code organization and reusability.
  • 🎣 Powerful Data Fetching and State Management: Integrated with React Query for declarative data fetching, caching, and state management, and Zustand for simple and lightweight application state management.
  • 🌐 Flexible Routing: Using React Router DOM for declarative route configuration, making it easy to build multi-page applications.
  • πŸ“£ User-Friendly Notifications: Integrated with React Hot Toast to provide elegant notification prompts.
  • πŸ“ž Convenient API Calls: Built-in Axios for sending HTTP requests.
  • 🎨 Modern CSS Framework: Pre-configured with Tailwind CSS for quickly building beautiful interfaces using a utility-first approach.
  • πŸ“ Code Quality Assurance: Integrated with ESLint and Prettier to provide code linting and automatic formatting, maintaining consistent code style.
  • βš™οΈ Easy to Configure: Sensible vite.config.ts configuration, including proxy settings and path aliases.

πŸ› οΈ Tech Stack

πŸ“¦ Usage

Follow these steps to start using this template:

  1. Create a New Repository: Click "Use this template" -> "Create a new repository" in the top right corner of this repository page. Alternatively, you can Fork this repository.
  2. Clone the Repository Locally:
    git clone https://github.com/guangzhaoli/react-ts-template.git
    cd react-ts-template
    
  3. Install Dependencies:
    npm install  # or using yarn: yarn install
    
  4. Start the Development Server:
    npm run dev   # or using yarn: yarn dev
    
    This will start the Vite development server and open the application in your browser. The address is usually http://localhost:3000.
  5. Start Developing:
    • Modify files in the src directory, and Vite will automatically perform hot updates.
    • Organize your code according to the directory structure.
  6. Build Production Version:
    npm run build # or using yarn: yarn build
    
    The built files will be located in the dist directory.
  7. Modify Project Name (Optional): Modify the project name according to your needs.

πŸ“‚ Directory Structure Overview

your-project-name/
β”œβ”€β”€ public/                      # Static assets (images, fonts, etc.)
β”‚   β”œβ”€β”€ vite.svg
β”‚   └── favicon.ico
β”œβ”€β”€ src/                         # Source code directory
β”‚   β”œβ”€β”€ assets/                  # Application-specific static assets (e.g., logo)
β”‚   β”‚   └── logo.svg
β”‚   β”œβ”€β”€ components/              # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ common/              # Common components (Button, Input, etc.)
β”‚   β”‚   β”‚   β”œβ”€β”€ Button.tsx
β”‚   β”‚   β”‚   └── Input.tsx
β”‚   β”‚   β”œβ”€β”€ layout/              # Layout components (Header, Footer, Sidebar, etc.)
β”‚   β”‚   β”‚   β”œβ”€β”€ Header.tsx
β”‚   β”‚   β”‚   └── Footer.tsx
β”‚   β”‚   └── features/            # Components for specific feature modules
β”‚   β”‚       β”œβ”€β”€ UserProfile.tsx
β”‚   β”‚       └── ProductCard.tsx
β”‚   β”œβ”€β”€ hooks/                     # Custom React Hooks
β”‚   β”‚   β”œβ”€β”€ useAuth.ts
β”‚   β”‚   └── useForm.ts
β”‚   β”œβ”€β”€ pages/                     # Application page components (corresponding to routes)
β”‚   β”‚   β”œβ”€β”€ HomePage.tsx
β”‚   β”‚   β”œβ”€β”€ UserPage.tsx
β”‚   β”‚   └── ProductDetailPage.tsx
β”‚   β”œβ”€β”€ routes/                    # Route configuration
β”‚   β”‚   └── index.tsx              # Define routes
β”‚   β”œβ”€β”€ services/                  # Services for interacting with the backend API
β”‚   β”‚   β”œβ”€β”€ api.ts                 # Encapsulated axios instance
β”‚   β”‚   β”œβ”€β”€ auth.ts                # API calls related to user authentication
β”‚   β”‚   └── users.ts               # API calls related to users
β”‚   β”œβ”€β”€ store/                     # Zustand state management
β”‚   β”‚   β”œβ”€β”€ index.ts               # Export all stores
β”‚   β”‚   └── userStore.ts           # User-related state
β”‚   β”œβ”€β”€ queries/                   # React Query related
β”‚   β”‚   β”œβ”€β”€ useUsersQuery.ts       # Query Hook for fetching user data
β”‚   β”‚   └── useProductsQuery.ts    # Query Hook for fetching product data
β”‚   β”œβ”€β”€ types/                     # TypeScript type definitions and interfaces
β”‚   β”‚   β”œβ”€β”€ user.d.ts
β”‚   β”‚   └── product.d.ts
β”‚   β”œβ”€β”€ utils/                     # Common utility functions
β”‚   β”‚   β”œβ”€β”€ helpers.ts
β”‚   β”‚   └── formatters.ts
β”‚   β”œβ”€β”€ App.tsx                    # Root component
β”‚   β”œβ”€β”€ main.tsx                   # Application entry point
β”‚   β”œβ”€β”€ index.css                  # Global styles (Tailwind directives)
β”‚   └── vite-env.d.ts              # Vite environment variable type definitions
β”œβ”€β”€ index.html                   # HTML entry file
β”œβ”€β”€ .eslintrc.cjs                # ESLint configuration
β”œβ”€β”€ .gitignore                   # Git ignore file
β”œβ”€β”€ postcss.config.cjs           # PostCSS configuration
β”œβ”€β”€ prettier.config.cjs          # Prettier configuration
β”œβ”€β”€ tailwind.config.cjs          # Tailwind CSS configuration
β”œβ”€β”€ tsconfig.json                # TypeScript configuration
β”œβ”€β”€ tsconfig.node.json           # TypeScript Node.js configuration
└── package.json                 # Project dependencies and scripts

πŸ’‘ Core Concepts and Usage

  • Route Configuration (src/routes/index.tsx): Use react-router-dom to define the application's routes. You can add and modify route rules in this file and associate them with page components (src/pages).
  • State Management (src/store): Zustand is used to manage application-level state. You can create different store files to manage different slices of state. For example, userStore.ts manages user-related state.
  • Data Fetching (src/queries and src/services):
    • The src/services directory contains service functions that interact with the backend API, using axios for requests. You can create different service files to organize your API calls.
    • The src/queries directory uses React Query to handle data fetching, caching, and state management. By defining Query Hooks (such as useUsersQuery.ts), you can conveniently fetch and manage asynchronous data in your components.
  • Type Definitions (src/types): It is recommended to place your application's type definitions and interfaces in the src/types directory for use throughout the project, enhancing code readability and maintainability.
  • Path Aliases (@): The vite.config.ts file configures the path alias @ to point to the src directory, making it easy to import modules in your code, for example: import Button from '@/components/common/Button';
  • API Proxy (vite.config.ts): If you need to proxy API requests to a backend service in the development environment, you can configure it in the server.proxy section of vite.config.ts. For example, requests starting with /api/v1 are configured to be proxied to http://localhost:8080.

🀝 Contributing

Contributions are welcome! Please submit issues and pull requests to improve this template. Ensure your contributions adhere to the project's code style and conventions.

πŸ“„ License

This project is open-sourced under the MIT License.


Hope this template helps you quickly start your next React TypeScript project! Enjoy coding!

Top categories

Loading Svelte Themes