Skip to main content

Lesson 3 of 10

Re-render Profiling - why-did-you-render

Before optimizing with useMemo and useCallback, you need to know which components are actually re-rendering and why. Guessing wastes time. Profiling tells you exactly what to fix.

20 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

React DevTools Profiler + why-did-you-render

React DevTools Profiler + why-did-you-render
// ---- React Native DevTools (RN 0.73+) ----
// Start app → shake device/press d → Open DevTools
// or: npx react-native start → press 'j' to open DevTools
//
// In Profiler tab:
// 1. Click Record (●)
// 2. Interact with your app (scroll the list, navigate)
// 3. Click Stop
// 4. Each grey bar = one render of a component
//    Width = render duration, color = why it rendered
//    Blue = re-rendered due to props/state change
//    Yellow = slow render (>10ms)

// ---- why-did-you-render ----
npm install @welldone-software/why-did-you-render

// wdyr.js - loaded BEFORE the app (in index.js)
if (__DEV__) {
  const whyDidYouRender = require('@welldone-software/why-did-you-render');
  whyDidYouRender(React, {
    trackAllPureComponents: true,   // auto-track React.memo components
    logOnDifferentValues: true,     // log even when old === new by reference
    collapseGroups: true,
  });
}

// Opt-in tracking for a specific component:
PostCard.whyDidYouRender = {
  logOwnerReasons: true,   // log which parent caused the re-render
};

// Common findings:
// "Previous props: { style: [Object] }, Next props: { style: [Object] }"
// → Inline style object - move to StyleSheet.create

// "Previous props: { onPress: [Function] }, Next props: { onPress: [Function] }"
// → New function reference every render - wrap with useCallback

// "Previous value: [1,2,3], Next value: [1,2,3] (different reference)"
// → Array from useMemo with wrong deps or no useMemo at all

Tip

Tip

Practice Rerender Profiling whydidyourender in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

Detecting redundant re-renders and profiling commit durations with React DevTools

Practice Task

Note

Practice Task - (1) Write a working example of Rerender Profiling whydidyourender 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 Rerender Profiling whydidyourender 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.

Topics in This Module

0/10 done