scrollbar automatically scroll down as new divs are added reactjs

import React, { useEffect, useRef } from 'react'

const Messages = ({ messages }) => {

  const messagesEndRef = useRef(null)

  const scrollToBottom = () => {
    messagesEndRef.current.scrollIntoView({ behavior: "smooth" })
  }

  useEffect(scrollToBottom, [messages]);

  return (
    <div>
      {messages.map(message => <Message key={message.id} {...message} />)}
      <div ref={messagesEndRef} />
    </div>
  )
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
automatic scroll down in react js react auto scroll with mouse react scroll div to bottom scroll bar in a chat reactjs component react on scroll end return to middle scroll to new message automatically react ref scroll bottom ref current scroll docs how to scroll the page to bottom in react react go to end of scroll container how to automatically scroll down in react js when adding divs in react keep the scroll down react typescript scroll to bottom css chat auto scroll down react react scroll to bottom on load on click scroll to bottom in react scrollbar position bottom by default using css react all time page scroll bar bottom using react react scroll-to-bottom vs react-scroll react scroll-to-bottom vs react scroll react-scroll-to-bottom example react always scroll to bottom how to make div scroll to bottom on message react react start scroll at bottom overflow begin from bottom react react make scroll start from the bottom scrolltobottom react change react scroll to bottom button automatically scroll to bottom on click react useref scroll to bottom react useref scroll to bottom scroll to bottom on click react auto scroll when overflow react react set scroll to scroll down in react js top to bottom scroll in react react js scroll to bottom on chat scroll to bottom using useref + react native scroll to bttom chat react js how to scroll new task react react scroll component scroll to bottom react how to scroll to bottom of page how to make page scroll down when new elements are rendered react go to bottom of scroll css react scrollto bottom reactjs after pages gets refreshed scrollto bottom reactjs react-scroll-to-bottom npm after page is refreshed react-scroll-to-bottom npm after page is refereshed srollToBottom reactjs react-scroll doesn't scroll to top when at the bottom react js scroll bottom of div scroll to bottom react hooks React component scroll to bottom scroll to bottom componenet react js scroll to end of a div in react react no auto scrolling to bottom react why page is auto scrolling to bottom react why is page auto scrolling hw to make scrollBar at buttom in react adding autoscroll to a div using react position scrollbar to bottom on scroll react chat app scroll to bottom first time react chat scroll to bottom react react scroll to bottom of screen react scroll to bottom of page how to scroll to the bottom in react js use useref to scroll to bottom first time only scroll chat box bottom react react-scroll-to-bottom typescript react scroll bottom div how to do already scrolled chat to bottom in react js Link react scroll to nothing load at bottom of overflow div react scroll to bottom add behaviour inside component react how to set behaviour in scroll to bottom component in react how to set behaviour in scroll to bottom in react how to scroll down reactjs scroll.scrollToBottom() react react on click go to bottom page react div scroll to bottom on scroll botton show button on reactjs react hook once error message received scroll down it site:stackoverflow.com react set scrollbar to bottom when rendered react set inital scroll to bottom react automatically scroll to bottom react function scroll bottom on load scroll auto in div react scroll to bottom of element react react div scroll to end react how to automatically scroll down scroll to bottom react js hook react after add content scroll to bottom page chat box auto scroll down react how to start scroll container at bottom css react scroll to bottom on enter submit react auto scroll to end react scroll div to end react react scroll to end react native div scroll from bottom scroll down react js auto scroll down when new messages come in react scrolltoBottom using ref in react react chat scroll to bottom scroll to bottom javascript react scroll to bottom of the page in react make scroll down react react when rendering component div scrol is at bottom scrollToBottom() in reactjs react go to bottom of page Window scroll to bottom reactjs react js scroll bar bottom [position react make div scroll to bottom react js scrollbar bottom react auto scroll by ref scroll message to the bottom in reactjs react scroll to bottom on reload reactjs auto scroll to bottom scroll to bottom using functiona in reactjs Scroll Div / Textarea To Bottom On Page Load in reactjs automatic scroll down in reactjs using css when i add automatically scroll bar down when it requires in css in react show bottom of div with scroll at first render how to show bottom of div with scroll at first render hoe to show bottom of div with scroll at first render hoe to show bottom of div with scrollbar at first render hoe to show automaticall bottom of div with scroll bar at first render hoe to make a scroll bar showing at bottom first react show bottom of content with scrollbar react scroll to bottom of div react how to scroll down in react js react scroll bottom scroll to bottom in react scroll bottom react react scroll to bottom inner react antd scroll to bottom how to make scroller automatically scroll to bottom of div container reactjs react scrollBottom react move scrollbar div overfow scroll bottom javascript after render react react js scroll to bottom of div react js scroll to bottom react scroll down react force scroll auto scroll react react scroll down to bottom of the page auto scroll to bottom of div react auto scroll div to bottom in react auto scroll div to bottom react how to auto scroll down react react ref scroll to bottom react scroll to bottom overflow div react scrol to bottom element show only on scroll bottom reacct div react autoscroll to bottom react scroll to bottom react scroll down how to scroll to end using ref in react scrollable Area react autumtic scroll down react React start end scroll auto scroll in react scroll bottom of div react on page render scroll to bottom react how to scroll down react auto scroll page up in react
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source