Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save SwarajDashDev/1697099c0d66b54eedd32d00f35a25bb to your computer and use it in GitHub Desktop.

Select an option

Save SwarajDashDev/1697099c0d66b54eedd32d00f35a25bb to your computer and use it in GitHub Desktop.
Learn how to use React Native's InteractionManager to postpone expensive calculations until after UI interactions, preventing frame drops and jank.

Insight

When a component triggers a costly operation—like parsing a large JSON payload or calculating layout—doing it immediately can block the UI thread and cause noticeable jank. React Native's InteractionManager lets you schedule such work to run after all ongoing interactions (animations, gestures, navigation transitions) have finished. This keeps animations smooth and preserves a responsive feel, especially on lower‑end devices.

Example

import { InteractionManager } from 'react-native';
import { useEffect, useState } from 'react';

export default function HeavyList() {
  const [data, setData] = useState<string[]>([]);

  useEffect(() => {
    // Defer heavy parsing until UI is idle
    InteractionManager.runAfterInteractions(() => {
      const raw = '["apple","banana","cherry"]'; // imagine a huge payload
      setData(JSON.parse(raw));
    });
  }, []);

  return data.map(item => <Item key={item} title={item} />);
}

Takeaway

Wrap any non‑essential, CPU‑intensive logic in InteractionManager.runAfterInteractions to let the UI finish its current work first. This simple pattern dramatically reduces frame drops during navigation or animation sequences without adding extra libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment