logoAnt Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
5.3.3
  • Ant Design of React
  • Getting Started
  • Real project with Umi
  • Use in create-react-app
  • Use in TypeScript
  • CSS Compatible
  • Customize Theme
  • Use custom date library
  • V4 to V5
  • Third-Party Libraries
  • Internationalization
  • FAQ
  • Contributing
  • Change Log
Install and Initialization
Import antd
Advanced Guides
Customize Theme
Alternative ways

Use in TypeScript

Use in create-react-appCSS Compatible

Resources

Ant Design Charts
Ant Design Pro
Ant Design Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Landing-Landing Templates
Scaffolds-Scaffold Market
Umi-React Application Framework
dumi-Component doc generator
qiankun-Micro-Frontends Framework
ahooks-React Hooks Library
Ant Motion-Motion Solution
China Mirror 🇨🇳

Community

Awesome Ant Design
Medium
Twitter
yuqueAnt Design in YuQue
Ant Design in Zhihu
Experience Cloud Blog
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
Change Log
FAQ
Bug Report
Issues
Discussions
StackOverflow
SegmentFault

Ant XTechMore Products

yuqueYuQue-Document Collaboration Platform
AntVAntV-Data Visualization
EggEgg-Enterprise Node.js Framework
kitchenKitchen-Sketch Toolkit
xtechAnt Financial Experience Tech
Theme Editor
Made with ❤ by
Ant Group and Ant Design Community

Let's create a TypeScript project by using create-react-app, then import antd step by step.

We build antd based on latest stable version of TypeScript (>=4.0.0), please make sure your project dependency matches it.


Install and Initialization

Ensure your system has installed latest version of yarn or npm.

Create a new cra-template-typescript project named antd-demo-ts using yarn.

$ yarn create react-app antd-demo-ts --template typescript

If you are using npm (we will use yarn in the following instructions, it's ok to replace yarn with npm)

$ npx create-react-app antd-demo-ts --template typescript

Then we go inside antd-demo-ts and start it.

$ cd antd-demo-ts
$ yarn start

Open browser at http://localhost:3000/, it renders a header saying "Welcome to React" on the page.

Import antd

$ yarn add antd

Modify src/App.tsx, import Button component from antd.

import React from 'react';
import type { FC } from 'react';
import { Button } from 'antd';
import 'antd/dist/reset.css';
import './App.css';
const App: FC = () => (
<div className="App">
<Button type="primary">Button</Button>
</div>
);
export default App;

OK, reboot with yarn start, you should now see a blue primary button displayed on the page. Next you can choose any components of antd to develop your application. Visit other workflows of create-react-app at it's User Guide.

antd is written in TypeScript with complete definitions, try out and enjoy the property suggestion and typing check.

Don't install @types/antd.

Advanced Guides

In the real world, we usually have to modify default webpack config for custom needs such as themes. We can achieve that by using craco which is one of create-react-app's custom config solutions.

Install craco and modify the scripts field in package.json.

$ yarn add @craco/craco
/* package.json */
"scripts": {
- "start": "react-scripts start",
- "build": "react-scripts build",
- "test": "react-scripts test",
+ "start": "craco start",
+ "build": "craco build",
+ "test": "craco test",
}

Then create a craco.config.js at root directory of your project for further overriding.

/* craco.config.js */
module.exports = {
// ...
};

Customize Theme

Ref to the Customize Theme documentation. Modify theme with ConfigProvider:

import React from 'react';
import { ConfigProvider } from 'antd';
export default () => (
<ConfigProvider
theme={{
token: {
colorPrimary: '#00b96b',
},
}}
>
<MyApp />
</ConfigProvider>
);

Alternative ways

Follow manual in Adding TypeScript to setup TypeScript development environment if you already create a project by Use in create-react-app.

  • Create React apps (with Typescript and antd) with no build configuration
  • react-app-rewire-typescript
  • ts-import-plugin
  • Migrating from create-react-app-typescript to Create React App