Ant Design Library has this component pre-built, and it is very easy to integrate as well. Button Component provides a way for users to take actions, and make choices, with a single tap. We can use the following approach in ReactJS to use the Ant Design Button Component.
Button Props:
- danger: It is used to set the danger status of the button.
- block: It is used as an option to fit the width of the button to its parent width.
- disabled: It is used to set the button in a disabled state.
- ghost: It is used to invert text and border colors and make the background transparent.
- href: It is used to define the redirect URL of the link button.
- htmlType: It is used to set the original HTML type of button.
- icon: It is used to set the icon component of the button.
- loading: It is used to set the loading status of the button.
- shape: It is used to set a button shape.
- size: It is used to set the size of the button.
- target: It is used as same as the target attribute of <a> tag.
- type: It is used to denote the type of button-like dashed, primary, etc.
- onClick: It is used to trigger a callback function with the click of the button.
Creating React Application And Installing Module:
-
Step 1: Create a React application using the following command:
npx create-react-app foldername
-
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
cd foldername
-
Step 3: After creating the ReactJS application, Install the required module using the following command:
npm install antd
Project Structure: It will look like the following.
Project Structure
Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.
App.js
import React from 'react'import "antd/dist/antd.css"; import { Button } from 'antd'; Â Â export default function App() { Â Â Â Â return ( Â Â Â Â <div style={{ display: 'block', width: 700, padding: 30 }}> Â Â Â Â Â Â <h4>Ant Design Button Component</h4> Â Â Â Â Â Â <Button>Default Button</Button> <br /> Â Â Â Â Â Â <Button type="primary">Primary Button</Button> <br /> Â Â Â Â Â Â <Button type="dashed">Dashed Button</Button> <br /> Â Â Â Â </div> Â Â ); } |
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
Reference: https://ant.design/components/button/
