How to create a Scroll To Bottom button in React JS ? Last Updated : 30 Nov, 2023 Comments Improve Suggest changes Like Article Like Report Learn to implement a "Scroll to Bottom" button in React using the useState() hook, a feature commonly seen in chat applications like WhatsApp and Telegram for effortless navigation to the end of a chat window. Prerequisites:NodeJS or NPMReact JSstyled-componentReact useState()Steps to Create the React Application And Installing Module:Step 1: Create a React application using the following command. npx create-react-app react-scroll-bottomStep 2: After creating your project folder i.e. foldername, move to it using the following command. cd react-scroll-bottomStep 3: Installing the dependencies required in this project npm install --save styled-componentsnpm install --save react-iconsProject Structure: The updated dependencies in package.json file will look like: "dependencies": { "react": "^18.2.0", "react-dom": "^18.2.0", "react-icons": "^4.12.0", "react-scripts": "5.0.1", "styled-components": "^6.1.1", "web-vitals": "^2.1.4",}Example: Create a webpage with a "Scroll To Bottom" button in React by managing state with useState(), toggling visibility based on scrolling direction, and using the scrollTo method for smooth navigation to the bottom, enhancing the user experience. JavaScript import { Fragment } from 'react'; import ScrollButton from './components/ScrollButton'; import { Content, Header } from './components/Styles'; function App() { return ( <Fragment> <Header>GeeksForGeeks Scroll To Bottom</Header> <ScrollButton /> <Content /> <Header>Thanks for visiting</Header> </Fragment> ); } export default App; JavaScript //ScrollButton.js import React, { useState } from 'react'; import { FaArrowCircleDown } from 'react-icons/fa'; import { Button } from './Styles'; const ScrollButton = () => { const [visible, setVisible] = useState(true) const toggleVisible = () => { const scrolled = document.documentElement.scrollTop; if (scrolled > 0) { setVisible(false) } else if (scrolled <= 0) { setVisible(true) } }; const scrollToBottom = () => { window.scrollTo({ top: document.documentElement.scrollHeight, behavior: 'auto' /* you can also use 'auto' behaviour in place of 'smooth' */ }); }; window.addEventListener('scroll', toggleVisible); return ( <Button> <FaArrowCircleDown onClick={scrollToBottom} style={{ display: visible ? 'inline' : 'none' }} /> </Button> ); } export default ScrollButton; JavaScript //Style.js import styled from 'styled-components'; export const Header = styled.h1` text-align: center; left: 50%; color: green; `; export const Content = styled.div` overflowY: scroll; height: 2500px; `; export const Button = styled.div` position: fixed; width: 100%; left: 50%; height: 20px; font-size: 3rem; z-index: 1; cursor: pointer; color: green; ` Step to Run Application: Run the application using the following command from the root directory of the project: npm startOutput: Now open your browser and go to http://localhost:3000 Comment More infoAdvertise with us Next Article How to create a Scroll To Bottom button in React JS ? gurjotloveparmar Follow Improve Article Tags : Web Technologies ReactJS React-Questions Styled-components Similar Reads How to Create a Scroll To Top Button in React JS ? You will see there are lots of websites, that are using a useful feature like if you're scrolling the webpage, and now you are at the bottom of that page then you can use this button to scroll up automatically like skip to the content. The following example covers create a Scroll To Top button in Re 3 min read How to Create a Scroll Back-to-Top Button in WordPress? The "Scroll Back-to-Top Button" in the website is a feature that looks like a button in the website, typically in the lower corner of the screen, which allows users to easily scroll back to the top of the page with a single click. A "Back to Top" button is a very easy little feature you often see on 3 min read How to add scroll into react-bootstrap Modal Body? React Bootstrap provides a straightforward way to create modal dialogue the for your web applications. However, sometimes the content within the modal body can be too long to fit within modal's default height. In such cases, you might add a scrollbar to the modal body to ensure users can scroll thro 2 min read How to Scroll to Bottom of Div in JavaScript ? Scrolling to the bottom of a div is a common task in web development, especially when dealing with chat applications, message boards, or any content where new information is frequently added at the bottom. There are several approaches to scrolling to the bottom of the div in JavaScript which are as 4 min read How to Create a Scroll Back to Top button using CSS? Scrolling to the top of a long webpage can be tedious, especially when you're at the bottom. A "Scroll to Top" button can improve user experience by allowing quick navigation back to the top with a single click, saving time and effort. This is particularly useful for mobile users who might otherwise 3 min read How to create Shopping Cart Button in ReactJS? A shopping cart button is one of the most used component in e-commerce websites or applications which allows users to add items to their cart . In this tutorial, we will learn how to create a shopping cart button in ReactJS using Material-UI. PrerequisitesJavaScript and JSXReact JSSteps to create Re 3 min read How to create Accordion in ReactJS ? Accordions contain creation flows and allow lightweight editing of an element. Material UI for React has this component available for us, and it is very easy to integrate. We can create it in React using the following approach.Approach to create Accordion in React JSTo create accordion in react we w 2 min read How to Ceate Swipe-able Button in Tailwind CSS and React? Creating swipe-enabled buttons in React applications can greatly improve user experience, especially on mobile devices, these buttons are typically used for actions like deleting, sharing, and liking items, in this article we'll show you how to create a swipe-enabled button using Tailwind CSS for st 3 min read How to create Popup box in React JS ? Popup boxes, also known as modal or dialog boxes, are common UI elements used to display additional content or interactions on top of the main page. Creating a popup box in React can be achieved using various approaches, including libraries or custom implementations. We will use the Reactjs-popup li 2 min read Write code to render a button in React JS React is a UI library. It renders components written in JSX.  You can build and render any components as per your usage. In this article, we will see how to render a button in React JS. Prerequisites:NodeJS or NPMReact JSJSX SyntaxApproach to render a button: Let us create a React project and a UI t 2 min read Like