title: How to use scrollintoview inside useeffect ( Cannot read properties of null (reading 'scrollIntoView') )
body: <p>I need to set my webPage from beginning to start. So I write code like this.</p>
  <pre><code>function BasicDetails() {
  
      React.useEffect(()=&gt;{
          scrollView();
      }, []);
  
      function scrollView() {
          document.getElementById('main-root').scrollIntoView({behavior: 'smooth'});
      }
      return (
          &lt;Nav&gt;
              &lt;div id=&quot;main-root&quot; style={{scrollBehavior: 'smooth'}}&gt;
                  &lt;div&gt;
                      &lt;Header pageTitle={'Shop Settings'}/&gt;
                      &lt;Button
                          onClick={saveBasicDetails}
                          variant=&quot;contained&quot;
                          id='save'
                          className={classes.saveButton}&gt;
                          SAVE
                      &lt;/Button&gt;
                  &lt;/div&gt;
  
                  &lt;BasicDetailsData style={{scrollBehavior: 'smooth'}} ref={childRef}/&gt;
              &lt;/div&gt;
          &lt;/Nav&gt;
      );
  }
  </code></pre>
  <p>But When I Tried to run my code, I have an <strong>error TypeError: Cannot read properties of null (reading 'scrollIntoView')</strong>
  So I tried many times but can't find the error.
  I am a new student for react, so. I don't know much about it.
  Anyone can help me with this...I really need your help..thank you.</p>