Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

739 B
Raw Blame
import { useEffect } from 'react'

export function useAnchor(hash: string): void {
    useEffect(() => {
        if (hash && document.getElementById(hash.slice(1))) {
            // Allow time for layout and repainting
            // (setTimeout because requestAnimationFrame resulted in final scroll position being slightly off)
            setTimeout(() => {
                // Check if there is a hash and if an element with that id exists
                const element = document.getElementById(hash.slice(1))
                if (!element) {
                    return
                }
                element.classList.add('animate-mark')
                element.scrollIntoView()
            }, 1000 / 60)
        }
    }, [hash])
}