last-train / website

A website for the last train podcast 🎙
https://thelasttrain.fm
MIT License
2 stars 0 forks source link

Scroll to section selected #26

Closed tiakindele closed 3 years ago

tiakindele commented 3 years ago

Right now, if you click on a section when in the archive page, it doesn't scroll down to the selected area.

  // layout.js
  useEffect(() => {
    const id = location.hash.substring(1); // location.hash without the '#'
    setTimeout(() => {
      const el = document.getElementById(id || 'hero');
      if (el) {
        el.scrollIntoView();
        el.focus();
      }
    }, 0);

    handleExternalLinks();
  }, []);