How to Make Images Load Faster in React Native

Most of the time, the react native image component is enough for showing images in your react native app. If your app has so many images to load then you may find issues such as flickering, cache miss, etc with the image component.

So, how to make your images optimized and load faster in react native?

React native fast image library provides you high performant image component with the following features.

  • Aggressive caching
  • Authorization headers
  • GIF
  • prioritize and preload images

You can install the library using the command given below.

yarn add react-native-fast-image

For ios, execute the following command too.

cd ios && pod install

Following is the example which uses the FastImage component of react native fast image library.

import React from 'react';
import {StyleSheet, View} from 'react-native';
import FastImage from 'react-native-fast-image';

const App = () => {
  return (
    <View style={styles.container}>
      <FastImage
        style={styles.image}
        source={{
          uri: 'https://cdn.pixabay.com/photo/2020/08/31/17/41/butterfly-5533130_1280.jpg',
          headers: {Authorization: 'default'},
          priority: FastImage.priority.normal,
        }}
        resizeMode={FastImage.resizeMode.contain}
      />
    </View>
  );
};

export default App;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  image: {
    width: 350,
    height: 200,
  },
});

Following is the output of the example.

That’s how you make images load faster in react native. I hope this tutorial helped you.

Leave a Reply

%d bloggers like this: