How to install and use antd in react js?
April 06, 2023Hi Friends π,
Welcome To aGuideHub!
To install and use antd in React js, you have to use the npm
or yarn
package manager that is how you can install the antd
library into your project.
Today, I am going to show you, how to install and use antd in react js.
Install Antd
Install the following packages to use antd
in react js.
npm
npm install antd
yarn
yarn install antd
Table of contents
- Create a new React JS project.
- Import Antd components.
- Use Antd components in the project.
Letβs start with the first step.
Step 1: Create a new React JS project.
First you have to install the React project. You should use create-react-app
command to create a new React project.
npx create-react-app my-app
cd my-app
npm start
Step 2: Import Antd components.
After installing antd, you have to import your React component. To do this, add the following line to the top of your component file.
import { Button } from 'antd';
Step 3: Use Antd components in the project.
In this blog, see the short example to use button
component ant design library.
<div>
<Button type="primary">Primary</Button>
</div>,
ReactJS use Antd example.
This code below is an example, we will import the button component from the ant library, and use button component as a primary
type of ant design library.
App.js
import { Button } from 'antd';
const App = () => (
<>
<div>
<Button type="primary">Primary</Button>
</div>,
</>
);
export default App;
Check the output of the above code example.
Here, we are provided code sandbox links for the above program to install and use antd in React js. Then you can use whenever you went and do the changes as per your requirements.
All the best π