ReactJS UI Ant Design BackTop Component
BackTop is a component in Ant Design that provides a button when the user has scrolled through the page to go back to the top of the page without the need to scroll back to the top. It will take the user to the top of the page with a smooth scrolling animation.
Ant Design Library has this component pre-built, and it is very easy to integrate as well. We can use this BackTop component using the following approach easily.
<BackTop> Scroll to Top </BackTop>
- duration: This property specify the time to return to top（ms）
- target: This property specifies the scrollable area dom node
- visibilityHeight: This property specifies that BackTop button will not show until the scroll height reaches this value
- onClick: This property specifies a callback function, which can be executed when you click the button
Creating React Application and Installing Module:
Step 1: Create a React application using the following command.
npx create-react-app demo
Step 2: After creating your project folder i.e. demo, move to it using the following command.
Step 3: After creating the ReactJS application, Install the antd library using the following command.
npm install antd
Example: Now write the following code in filename App.js.
Running the application: Run the application by using the following command.
Output: Now open your browser and go to http://localhost:3000/, You will see the following output.