Ant Design Pro

repository·master·Indexed 13 days ago

https://github.com/ant-design/ant-design-pro

An out-of-the-box UI solution for enterprise applications provided as a React boilerplate. Version 6.0.2 features a modern stack including React 19, Umi Max 4, Ant Design 6, and Tailwind CSS v4. It includes built-in support for global state management via useModel, server state with React Query, internationalization, and OpenAPI service code generation.

Tokens
24.2K
Snippets
103
Records
115
Agent score
97%

What's inside Ant Design Pro

  1. Manage global state with useModel and getInitialState

    master

    Ant Design Pro provides several ways to manage state:

    1. useModel (Lightweight Global State): Create files in src/models/ to automatically register global models. Access them anywhere using useModel('modelName').
    2. getInitialState (Initial State): Defined in src/app.tsx, this runs once at application startup. It is ideal for fetching global information like user identity or permissions. Access it via useModel('@@initialState').
    3. useRequest: A hook for data fetching.
    4. React Query: For advanced server-state management using @tanstack/react-query.
    // 1. Define a model in src/models/counter.ts
    import { useState } from 'react';
    export default function useCounter() {
      const [count, setCount] = useState(0);
      const increment = () => setCount(c => c + 1);
      return { count, increment };
    }
    
    // 2. Use the model in a component
    import { useModel } from '@umijs/max';
    const { count, increment } = useModel('counter');
    
    // 3. Access Initial State (defined in src/app.tsx)
    import { useModel } from '@umijs/max';
    const { initialState } = useModel('@@initialState');
    
    // 4. React Query usage
    import { useQuery } from '@tanstack/react-query';
    const { data, isLoading } = useQuery({
      queryKey: ['user', id],
      queryFn: () => getUser(id),
    });
  2. Manage utoopack (@utoo/pack) updates

    master

    The @utoo/pack bundler is a transitive dependency of @umijs/max (via umi and @umijs/preset-umi).

    Do not upgrade @utoo/pack independently in Ant Design Pro. Upgrading it manually can cause version mismatches with the @umijs/max bundler and will be overwritten during the next @umijs/max update. The correct way to upgrade the bundler is to upgrade @umijs/max itself, allowing the Umi team to manage compatibility.

  3. Implement permissions with access

    master

    Permissions are defined in src/access.ts based on the initialState. You can apply permissions in two ways:

    1. Route-level: Add the access key to your route configuration in config/routes.ts.
    2. Component-level: Use the <Access> component for declarative control or the useAccess hook for imperative logic.
    // File: src/access.ts
    export default function access(initialState: { currentUser?: API.CurrentUser }) {
      const { currentUser } = initialState;
      return {
        canAdmin: currentUser?.access === 'admin',
        canUser: !!currentUser,
      };
    }
    
    // Component-level usage
    import { Access, useAccess } from '@umijs/max';
    
    // Declarative
    <Access accessible={access.canAdmin}>
      <AdminPanel />
    </Access>
    
    // Imperative
    const access = useAccess();
    if (access.canAdmin) { /* ... */ }
  4. Use Claude Code Skills for Ant Design Pro

    master

    Ant Design Pro includes built-in Claude Code Skills located in .claude/skills/. These skills allow you to automate upgrades and query component information directly within Claude Code.

    If your project was cloned from this repo, these skills are included. To refresh them with the latest definitions, run:

    npx skills add ant-design/ant-design-pro

    Available Skills

    SkillTriggerDescription
    /pro-upgrade"upgrade pro", "update to latest"Auto-upgrades to the latest Ant Design Pro version by diffing the latest template and merging changes while preserving your business code.
    /antdantd-related code or questionsQueries Ant Design component APIs, props, tokens, and demos; lints for deprecated usage; and assists in version migration via @ant-design/cli.

    Usage Examples

    # Upgrade the project to the latest Pro version
    /pro-upgrade
    
    # Query antd component info, debug issues, run lint, etc.
    /antd
    # Upgrade the project to latest Pro version
    /pro-upgrade
    
    # Query antd component info, debug issues, run lint, etc.
    /antd
  5. Switch Ant Design Pro to Simple mode

    master

    To strip away demo pages and unused dependencies to create a minimal project, use the npm run simple command.

    Warning: Always commit your current changes before running this command so you can revert if necessary.

    git add -A && git commit -m "chore: save before simple"
    npm run simple
    npm install
  6. Upgrade Node.js minimum version to 22

    master

    As of the v6.1.0 evaluation, Node.js 20 has reached End of Life (EOL). It is recommended to upgrade the minimum required Node.js version to 22 (Active LTS) to ensure security and ecosystem compatibility (e.g., with vitest and @biomejs/biome).

    To perform this upgrade, update the following:

    1. Set engines.node to ">=22.0.0" in package.json.
    2. Update CI workflow matrices (e.g., node-version or node_version) to use version 22.
    3. Update any project documentation (like CLAUDE.md) that references Node.js version requirements.
    // package.json
    {
      "engines": {
        "node": ">=22.0.0"
      }
    }
  7. Manage Global State with useModel

    master

    Ant Design Pro uses a model-based approach for global state via Umi's useModel hook.

    1. Create a model: Create a file in src/models/ (e.g., src/models/myModel.ts). The filename becomes the model key.
    2. Export a Hook: The file must export a custom Hook as the default export.
    3. Consume the state: Use useModel('filename') in any component to access the exported data.
    // src/models/myModel.ts
    export default function useMyModel() {
      return { data: 'some state' };
    }
    
    // In a component
    import { useModel } from '@umijs/max';
    const { data } = useModel('myModel');
  8. Use Claude Code Skills for Pro Upgrade and Ant Design

    master

    If you are using Claude Code, you can leverage built-in skills to manage your project.

    /pro-upgrade — Project Upgrade Assistant

    Automatically upgrades your project to the latest Ant Design Pro version by diffing the latest template against your current code. It handles dependencies, config changes, and code pattern migrations.

    /antd — Ant Design CLI Helper

    Provides access to @ant-design/cli for querying component information and debugging.

    • npx antd info <Component>: View props, types, and version info.
    • npx antd demo <Component> <demo>: Get working code examples.
    • npx antd lint ./src: Check for deprecated or problematic usage.
    • npx antd doc <Component>: Access full component documentation.

    To install or update these skills in your project, run: npx skills add ant-design/ant-design-pro

  9. Simplify to Simple Version

    master

    The npm run simple command converts your project into a 'Simple Version' by deleting demo pages and unused dependencies.

    WARNING: This operation is irreversible.

    You must commit all current changes before running this command.

    git add -A && git commit -m "chore: save before simple"
    npm run simple
    npm install
  10. Validate project after upgrade

    master

    After performing dependency upgrades, follow this checklist to ensure project stability:

    1. Linting: Run npm run lint (verifying both Biome and tsc).
    2. Antd Linting: Run npx antd lint ./src to check for Ant Design component usage issues.
    3. Build: Run npm run build to ensure the production build succeeds.
    4. Testing: Execute all tests to ensure no regressions were introduced.
    5. Development: Run npm start to verify the development server works.
    6. Visual Inspection: Perform a visual spot-check of critical pages: Login, Dashboard, Table-list, and Forms.
    npm run lint
    npx antd lint ./src
    npm run build
    npm test
    npm start
  11. Generate API Service Code with OpenAPI

    master

    Ant Design Pro can automatically generate API service code from an OpenAPI specification.

    Workflow:

    1. Configure your OpenAPI settings in config/oneapi.json.
    2. Run npm run openapi to generate the code.
    3. The generated code will be placed under src/services/.

    CRITICAL: Never edit the generated code in src/services/ant-design-pro/ manually. If changes are needed, modify config/oneapi.json and regenerate the code.

    npm run openapi