ReactJS UI Ant Design Anchor Component
Ant Design Library has this component pre-built, and it is very easy to integrate as well. Anchor Component is used to allow the hyperlinks to scroll on one page. It is useful when we want to display the anchor hyperlinks on the page and allow the user to jumps between them easily. We can use the following approach in ReactJS to use the Ant Design Anchor Component.
- affix: It is used to denote the fixed mode of Anchor.
- bounds: It is used to bound the distance of the anchor area.
- getContainer: It is a function to get the scrolling container.
- getCurrentAnchor: It is used to customize the anchor highlight.
- offsetTop: When calculating the position of the scroll, it is used to denote the pixels to offset from top.
- showInkInFixed: It is used to indicate whether to show ink-balls or not when affix is set to false.
- targetOffset: It is used to denote the Anchor scroll offset.
- onChange: It is a callback function that is triggered on the anchor link change.
- onClick: It is a callback function that is used to set the handler to handle click event.
- href: It is used to denote the target of hyperlinks.
- target: It is used to specify where to display the linked URL.
- title: It is used to define the content of hyperlinks.
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:
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.
Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.
Step to Run Application: Run the application using the following command from the root directory of the project:
Output: Now open your browser and go to http://localhost:3000/, you will see the following output: