title: Scroll to top does not work in React after click
body: <p>I have a long list of categories and on select (click) the categories are substituted by actual items (categories contain items). What I want to do is scroll to top on category select but it does not work for some reason. Here is what I have so far:</p>
  <pre class="lang-js prettyprint-override"><code>const scrollToTop = () =&gt; {
    window.scrollTo({
      top: 0,
      left: 0,
      behavior: &quot;smooth&quot;
    });
  };
  
  export const CategoryCard = (props) =&gt; {
  
  const onCategorySelect = () =&gt; {
    scrollToTop();
  }
  
  return ({isCategoryType(item) ? (
    &lt;div
      onClick={() =&gt; {
        onCategorySelect();
      }}
     &gt;
      &lt;Typography
        onClick={e =&gt; e.preventDefault()}
      &gt; Category one &lt;/Typography&gt;
     &lt;/div&gt;) : (...)
  })
  
  </code></pre>