react how to scroll to element
import React, { useRef } from 'react'
const scrollToRef = (ref) => window.scrollTo(0, ref.current.offsetTop)
// General scroll to element function
const ScrollDemo = () => {
const myRef = useRef(null)
const executeScroll = () => scrollToRef(myRef)
return (
<>
<div ref={myRef}>I wanna be seen</div>
<button onClick={executeScroll}> Click to scroll </button>
</>
)
}
class ReadyToScroll extends Component {
constructor(props) {
super(props)
this.myRef = React.createRef()
}
render() {
return <div ref={this.myRef}></div>
}
scrollToMyRef = () => window.scrollTo(0, this.myRef.current.offsetTop)
// run this method to execute scrolling.
}
Also in JavaScript:
- how to remove menu bar in electron app without removing frame
- check for substring javascript
- url redirect javascript
- function inside function javascript
- how to get element of an array in javascript
- locak storage for table\ js
- react native textinput no keyboard
- how to create react native project at specific version
- react native reducer example
- how do you make a sprite with javascript
- javascript index of min value in array
- angular valuechanges get id
- package json proxy
- json array on jasper
- javascript delete cookie
- how to pad string js
- include other js files in a js file
- javascript and python graphs for data analysis
- sort a string in javascript
- remove item from array javascript
- trigger window resize
- Vuejs v-model when enter pressed
- find smallest length string in an array js
- hide component on click vue