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

256
Views
How to eager load an list or array of objects in NextJS?

I have the following next/image in one of my pages, with priority set to true to eager load the asset from the state

const [imageToUse, setImageToUse] = useState(initialImage);

<Image src={imageToUse} alt='scrolls' priority={true} ... />

I have set state in such a way that it would listen on scroll event and have it calls the state imageToUse from a new image as the user scrolls:

 const cycleImages = {
    1: "/header/_0011.webp",
    2: "/header/_0012.webp",
    3: "/header/_0013.webp",
    ....
    37: "/header/_0047.webp",
}

 useEffect(() => {
    // scrolled at every 30 pixels
    const y = clientWindowHeight / 30;
    // Scroll event distance + cycle through a list of objects
    let label = Math.min(Math.floor(y) + 1, 37)
    // Set imageToUse
    let image = cycleImages[label]
    setImageToUse(image)
}

The above logic works, but the only problem I have is that <Image /> only eager loads the initial image or the image that is about to be scrolled through - whereas I want it to eager load all 37 images and to avoid fetching ONLY when it is scrolls to and create stutter (i.e. bad user experience).

So how do I eager load all 37 images in NextJS?

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!