DEV Community

Cover image for How to optimize React Native App
Raaj
Raaj

Posted on

1 1

How to optimize React Native App

A great user experience should be the core objective of any app development. Although React Native tries to provide everything you need to develop a performant application, there are occasions where you have to manually optimize your app. To do this, developers need to have a performance optimization mindset from the start of their projects.

Ways to Optimize the React Native App

1. Use FlatList
2. Remove all console statements
3. Memoize expensive computations
4. Use Relevant sized images
5. Remove unnecessary libraries and features
6. Use Hermes

1. Use FlatList to render large lists in React Native

If you have a large list, rendering all the items at once can cause a performance issue, but lazy loading with FlatList will improve performance

import React from 'react'
import {FlatList} from 'react-native'

const data = [
  {
    id: 1,
    text: 'First'
  },
  {
    id: 2,
    text: 'Second'
  },
  ...
]

const App = () =>{
    const renderItem = ({item}) =>(
        <View>
          <Text>{item.text}</Text>
        </View>
    )
    return (
        <FlatList
          data={data}
          renderItem={renderItem}
          keyExtractor={item => item.id}
        />
    )
}
Enter fullscreen mode Exit fullscreen mode

2. Remove all console statements

While you could install some plugins such as babel-plugin-transform-remove-console to remove these statements from production

3. Memoize expensive computations

React introduced the memo HOC (Higher Order Component) for preventing unnecessary re-rendering and the useMemo hook for optimizing expensive computations.

4. Adjust (resize and scale down) image sizes

Images can contribute significantly to performance issues in React Native applications. So use relevant sized Images to increase the loading performance of your App

5. Remove unnecessary libraries and features

Each library in a React or React Native application leaves some footprint on the application. This is why you should only add libraries and features you need in your app and remove irrelevant dependencies and libraries. Animations, navigations, tabs, and other features can contribute to the screen load time and so the more they are on the screen, the worse the performance.

6. Use Hermes

Hermes is a JavaScript Engine developed by Facebook in 2019. It is one of the must-have features for improving app performance, reducing memory usage, decreasing app size, and improving the app start-up time.
Hermes is not currently enabled by default in React Native but you can easily enable it in your app.
To enable Hermes on Android, edit your android/app/build.gradle file and add the following rules.

project.ext.react = [
      entryFile: "index.js",
      enableHermes: true
  ]
Enter fullscreen mode Exit fullscreen mode

Billboard image

Use Playwright to test. Use Playwright to monitor.

Join Vercel, CrowdStrike, and thousands of other teams that run end-to-end monitors on Checkly's programmable monitoring platform.

Get started now!

Top comments (0)

Image of Bright Data

Maintain Seamless Data Collection – No more rotating IPs or server bans.

Avoid detection with our dynamic IP solutions. Perfect for continuous data scraping without interruptions.

Avoid Detection

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay