2016-12-22 14:24:50 +08:00
---
2019-12-17 22:25:28 +08:00
order: 4
2023-06-12 16:45:59 +08:00
title: Usage with create-react-app
2016-12-22 14:24:50 +08:00
---
2023-06-12 16:45:59 +08:00
[create-react-app ](https://create-react-app.dev/ ) is one of the best React application development tools, This article will try to use `create-react-app` to create a project, and introduce antd.
2016-12-22 14:24:50 +08:00
## Install and Initialization
2023-06-12 16:45:59 +08:00
Before all start, you may need install [yarn ](https://github.com/yarnpkg/yarn/ ) or [pnpm ](https://pnpm.io/ ).
2016-12-22 14:24:50 +08:00
2023-06-12 16:45:59 +08:00
< InstallDependencies npm = '$ npx create-react-app antd-demo' yarn = '$ yarn create react-app antd-demo' pnpm = '$ pnpm create react-app antd-demo' > < / InstallDependencies >
2016-12-22 14:24:50 +08:00
2019-05-07 14:57:32 +08:00
The tool will create and initialize environment and dependencies automatically, please try config your proxy setting or use another npm registry if any network errors happen during it.
2016-12-22 14:24:50 +08:00
2023-06-12 16:45:59 +08:00
Then we go inside project and start it.
2016-12-22 14:24:50 +08:00
```bash
$ cd antd-demo
2017-01-09 13:50:49 +08:00
$ yarn start
2016-12-22 14:24:50 +08:00
```
2023-06-12 16:45:59 +08:00
Open the browser at http://localhost:3000/. It renders a header saying `Welcome to React` on the page.
2016-12-22 14:24:50 +08:00
## Import antd
2017-06-30 03:05:48 +08:00
Below is the default directory structure.
2016-12-22 14:24:50 +08:00
```
├── README.md
├── package.json
├── public
│ ├── favicon.ico
│ └── index.html
├── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── index.css
│ ├── index.js
│ └── logo.svg
└── yarn.lock
```
2017-01-09 13:50:49 +08:00
Now we install `antd` from yarn or npm.
2016-12-22 14:24:50 +08:00
```bash
2017-05-28 17:03:34 +08:00
$ yarn add antd
2016-12-22 14:24:50 +08:00
```
Modify `src/App.js` , import Button component from `antd` .
```jsx
2019-12-15 22:25:56 +08:00
import { Button } from 'antd';
2023-06-12 16:45:59 +08:00
import React from 'react';
2016-12-22 14:24:50 +08:00
2019-12-15 22:25:56 +08:00
const App = () => (
< div className = "App" >
< Button type = "primary" > Button< / Button >
< / div >
);
2016-12-22 14:24:50 +08:00
export default App;
```
2021-09-23 22:13:05 +08:00
OK, 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 its [User Guide ](https://create-react-app.dev/docs/getting-started ).
2016-12-22 14:24:50 +08:00
2019-12-15 22:25:56 +08:00
We are successfully running antd components now, go build your own application!