Answers for "react, scroll element into view"

0

react, scroll element into view

const ScrollDemo = () => {
   const myRef = useRef(null)

   const executeScroll = () => myRef.current.scrollIntoView()    
   // run this function from an event handler or an effect to execute scroll 

   return (
      <> 
         <div ref={myRef}>Element to scroll to</div> 
         <button onClick={executeScroll}> Click to scroll </button> 
      </>
   )
}
Posted by: Guest on March-29-2022

Code answers related to "react, scroll element into view"

Code answers related to "Javascript"

Browse Popular Code Answers by Language