Skip to content

Instantly share code, notes, and snippets.

@codewithbernard
Created November 29, 2021 11:33
Show Gist options
  • Select an option

  • Save codewithbernard/2d36e339a9d7db8cbcb3e68ba51dd11b to your computer and use it in GitHub Desktop.

Select an option

Save codewithbernard/2d36e339a9d7db8cbcb3e68ba51dd11b to your computer and use it in GitHub Desktop.
import React, { useRef } from 'react';
const App = () => {
const scollToRef = useRef();
return (
<div className="container">
<button onClick={() => scollToRef.current.scrollIntoView()}>
Scroll
</button>
<div ref={scollToRef}>You scrolled to me</div>
</div>
);
};
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment