Sitemap
Adnan Sahinovic

Adnan Sahinovic

I build and secure mobile apps at scale. Mobile tech lead, React Native community contributor, and Creator of rnsec - first security scanner for React Native

React & React Native: Measuring Screen Load Time

An easy way to create custom performance monitoring for React and React Native apps

2 min readApr 29, 2024

--

Press enter or click to view image in full size
Photo by Cody Fitzgerald on Unsplash

This article aims to measure the time it takes for a screen to load data and draw its UI elements. These steps must be taken before the user can interact with the UI.

Measuring load time is not just a task, it's a critical step to ensure a fast and smooth user experience. It's your key to determining if new feature development or refactoring positively or negatively impacted the app’s performance.

Get Adnan Sahinovic’s stories in your inbox

Join Medium for free to get updates from this writer.

Rest assured, after finishing this guide, you’ll build a custom hook that can be seamlessly plugged into any React, or React Native app and start measuring load time.

Implementation

Let's dive into the implementation. Our first task is to define the properties we want to use. Our goal is to create a solution that can be effortlessly integrated into any screen and start measuring time.

  • screenName: defined screen name
  • isLoading: indicating if loading is finished and a user can start with interaction

With these two in place, we can start building a custom hook.

hook to start measuring screen load
  • In useEffect we start measuring time with performance.now() once the user arrives on the screen and sets the start time.
  • The performance.now() method returns a high-resolution timestamp in milliseconds.
  • After the data is loaded, we set the endTime and calculate the time to load by measuring the difference between the end and start times.

Start Measuring

Let’s simply use what we have built so far and start measuring time. To do this, we need to simply import and call useGetPerformance hook with its properties.

React Native

note: we won’t be implementing full fetching as this is not part of the tutorial

React

note: we won’t be implementing full fetching as this is not part of the tutorial

Now, open a console; you should see a log message with calculated milliseconds.

results: time to load end render in milliseconds

We usually want to log load time to monitor it in real-time and take action. You can start logging data using the Amplitude or Datadog event logging tool.

Datadog: https://docs.datadoghq.com/service_management/events/

Amplitude: https://www.docs.developers.amplitude.com/

Happy coding!

--

Adnan Sahinovic
Adnan Sahinovic

Written by Adnan Sahinovic

I build and secure mobile apps at scale. Mobile tech lead, React Native community contributor, and Creator of rnsec - first security scanner for React Native