title: How to get scrollPosition using getSnapshotBeforeUpdate() in React Js?
body: <p>I am trying to get scrollPosition using getSnapshotBeforeUpdate lifecycle method. I went through below React official site to understand about new life cycle method <a href="https://reactjs.org/docs/react-component.html#getsnapshotbeforeupdate" rel="nofollow noreferrer">getSnapshotBeforeUpdate</a>  </p>
  
  <p>But I am not able to find any scroll position. I console.log all the output, but didn't find anything in console. </p>
  
  <p>This is my code file: 
  import React from 'react';</p>
  
  <pre><code>class ScrollingList extends React.Component {
      constructor(props){
          super(props);
          this.listRef = React.createRef();
      }
  
      getStaticContent() {
          const result = [];
          for( let i= 1; i &lt;=100; i++){
              result.push(&lt;li key={i}&gt;{i} &gt; This is paragraph line-{i}&lt;/li&gt;);
          }
          return result;
      }
  
      getSnapshotBeforeUpdate(preProps, preState) {
          // const list = this.listRef.current;
          // console.log(list);
          if(preProps.list.length &gt; this.props.list.length) {
              const list = this.listRef.current;
              console.log(list);
              return list.ScrollingHeight - list.ScrollTop;
          }
          return null;
      }
  
      componentDidUpdate(preProps, preState, snapshot) {
          console.log(snapshot);
          if (snapshot !== null) {
              const list = this.listRef.current;
              list.scrollTop = list.scrollHeight - snapshot;
          }
      }
  
      render() {
          return(
  
              &lt;div ref={this.listRef}&gt;
                      {/* &lt;div className="content-wrap"&gt;
                          &lt;ul&gt;
                              {this.getStaticContent()}
                          &lt;/ul&gt;
                      &lt;/div&gt; */}
              &lt;/div&gt;
  
          );
      }
  }
  
  export default ScrollingList;
  </code></pre>
  
  <p>Error: TypeError: Cannot read property 'length' of undefined</p>
  
  <p>How I can get scroll position using this life cyle method?</p>