What is the correct way to work with string in React? I really like smooth scrolling due to better UX. Since manipulating the DOM in React is an anti-pattern, I ran into a problem: how to scroll smoothly to some position / element? I usually change the scrollTop value of an element, but this is a DOM manipulation that is not allowed.
Jsbin
code:
import React from 'react'; import ReactDOM from 'react-dom'; class App extends React.Component { handleClick = e => { for (let i = 1; i <= 100; i++) { setTimeout(() => (this.node.scrollTop = i), i * 2); } }; render() { const someArrayToMap = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; return ( <div ref={node => this.node = node} style={{overflow: 'auto', height: '100vh'}}> <button onClick={this.handleClick}>CLICK TO SCROLL</button> { [...someArrayToMap, ...someArrayToMap, ...someArrayToMap, ...someArrayToMap, ...someArrayToMap, ...someArrayToMap, ...someArrayToMap].map((e, i) => <div key={i}>some text here</div>) } </div> ); } } ReactDOM.render(<App />, document.getElementById('root'));
How to achieve this in Response mode?
sympi source share