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.
vite.config.ts
configuration, including proxy settings and path aliases.Follow these steps to start using this template:
git clone https://github.com/guangzhaoli/react-ts-template.git
cd react-ts-template
npm install # or using yarn: yarn install
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
.src
directory, and Vite will automatically perform hot updates.npm run build # or using yarn: yarn build
The built files will be located in the dist
directory.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
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
).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.src/queries
and src/services
):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.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.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.@
): 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';
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
.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.
This project is open-sourced under the MIT License.
Hope this template helps you quickly start your next React TypeScript project! Enjoy coding!