Answers for "react scroll to bottom"

6

scroll to top in react

componentDidMount() {
  window.scrollTo(0, 0)
}
Posted by: Guest on August-28-2020
2

scroll to top in react

useEffect(() => {
  window.scrollTo(0, 0)
}, [])
Posted by: Guest on August-28-2020
0

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>
  )
}
Posted by: Guest on October-12-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language