DEV Community

Zain Ahmed for yar Coder

Posted on • Edited on

2

Make Image Loading (React Native)

Alt Text
Suppose we have array of 10 Objects and every object has a url of image which are multi mb’s like 50mb, 45mb etc, so it take time to display image on screen bcz to fetch image from url it take time’s , here is the solution while image is downloading we can show any default image or loader for every image in loop , let start!
here is our array
Alt Text
Alt Text
here is my main component for render the array with flatlist ,
inside flat list i create a component name ImageItem,
Alt Text
i declare loading State for show load or default image , while fetching image
in render method i just made a condition that if loading is true i am showing loader and if loading is false i ll show image
the Image tag have 2 props which will use for this main part , onLoadStart which execute when image fetching start and i update the state loading true,
onLoadEnd will execute when image fetching is complete and ready to display so i update loading false , its that simple,

hope you learn from it , support me on my YouTube channel

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay