Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save codewithbernard/f6f0b202ec1e5076d69bf0e8e1149588 to your computer and use it in GitHub Desktop.
import React, { createRef } from 'react';
class App extends Component {
constructor(props) {
super(props);
this.scollToRef = createRef();
}
render() {
return (
<div className="container">
<button onClick={() => this.scollToRef.current.scrollIntoView()}>
Scroll
</button>
<div ref={this.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