Created
November 29, 2021 11:35
-
-
Save codewithbernard/f6f0b202ec1e5076d69bf0e8e1149588 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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