Lesson 6 of 10
Image Handling - expo-image & Caching
The default React Native Image component has no disk cache on iOS and a basic one on Android. In production apps with image-heavy feeds, expo-image or react-native-fast-image is essential for performance and battery life.
expo-image - Production Image Loading
import { Image } from 'expo-image';
// expo-image advantages:
// - Shared disk cache (image fetched once is served from disk on all future views)
// - AVIF and WebP format support (30-50% smaller files vs JPEG)
// - Blurhash/thumbhash placeholders (shows colored blur while loading)
// - Smooth transition from placeholder to loaded image
// - Better memory management (pools decoded bitmaps)
function Avatar({ uri, thumbhash }: { uri: string; thumbhash?: string }) {
return (
<Image
source={{ uri }}
placeholder={thumbhash ? { thumbhash } : require('../assets/avatar-placeholder.png')}
contentFit="cover" // equivalent to resizeMode="cover"
transition={200} // fade in over 200ms
recyclingKey={uri} // hint to reuse view cell (FlatList optimization)
style={{ width: 48, height: 48, borderRadius: 24 }}
/>
);
}
// ---- Clearing image cache (useful for logout / cache busting) ----
import { clearDiskCache, clearMemoryCache } from 'expo-image';
async function onLogout() {
await clearDiskCache(); // clears all cached images from disk
clearMemoryCache(); // clears in-memory decoded image bitmap cache
}Tip
Tip
Practice Image Handling expoimage Caching in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Image resizing modes, density scaling, and disk cache pipelining
Practice Task
Note
Practice Task - (1) Write a working example of Image Handling expoimage Caching from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Image Handling expoimage Caching is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react native code.
Finished this lesson?