Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

ReactJS UI Ant Design Anchor Component

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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.

Anchor Props:

  • 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.

Link Props:

  • 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:

    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.


import React from 'react'
import "antd/dist/antd.css";
import { Anchor } from 'antd';
const { Link } = Anchor;
export default function App() {
  return (
    <div style={{
      display: 'block', width: 700, padding: 30, height: 1000,
      <h4>ReactJS Ant-Design Anchor Component</h4>
        <Link href="#" title="Course Link" />
        <Link href="#" title="Exam Link">
          <Link href="#" title="Study Material" />
          <Link href="#" title="Exam Prepration" />
          <Link href="#" title="Test Link" />

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:


My Personal Notes arrow_drop_up
Last Updated : 30 May, 2021
Like Article
Save Article
Similar Reads
Related Tutorials