Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
Anchor links jump to accurate position after images are loaded

Similar to this post, my case doesn't use React Router or jQuery. It's just a single page and vertically long. As for the title, anchor links don't jump to the accurate position since the images are not loaded and cannot calculate the precise location. I found a solution and tried as below, but not working. How can I solve it?

UPDATE: As in the comment, setting image sizes didn't work either.

export const useScrollToLocation = () => {
const scrolledRef = useRef(false)
const { hash } = useLocation()
const hashRef = useRef(hash)

useEffect(() => {
    if (hash) {
        // We want to reset if the hash has changed
        if (hashRef.current !== hash) {
            hashRef.current = hash
            scrolledRef.current = false
        }

        // only attempt to scroll if we haven't yet (this could have just reset above if hash changed)
        if (!scrolledRef.current) {
            const id = hash.replace('#', '')
            const element = document.getElementById(id)
            if (element) {
                element.scrollIntoView({ behavior: 'smooth' })
                scrolledRef.current = true
            }
        }
    }
})

}

function App() {
    return (
        <>
            <useScrollToLocation>
                <Navigation />   
                <Hero />
                <Concept />
                <Shop />
                <Footer />
            </useScrollToLocation>
        </>
    )
}

export default App
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!