Websites v4 docs v8.3.1
    Preparing search index...

    Function useScrollTo

    • Hook for smoothly scrolling to an element, identified by its id, class name, or a ref. Since lazy-loaded content elsewhere on the page can shift the target's position after the initial scroll starts, it watches the page for a short window afterwards and corrects the scroll position if it moves.

      Returns (target: ScrollTarget, options?: UseScrollToOptions) => boolean

      A scrollTo(target, options) function which returns true if a matching element was found and the scroll started, or false if no matching element exists, so callers can fall back to something else (e.g. navigating elsewhere).

      const scrollTo = useScrollTo();

      <button onClick={() => scrollTo('feefo-reviews', { yOffset: 80 })}>Read reviews</button>
      <button onClick={() => scrollTo(reviewsRef)}>Read reviews</button>