All skills
dimillian avatar

/react-component-performance

@3db84e6 official
by Thomas Ricouarddimillian/skills4k stars
206

Analyze and optimize React component performance issues (slow renders, re-render thrash, laggy lists, expensive computations). Use when asked to profile or improve a React component, reduce re-renders, or speed up UI updates in React apps.

Use this Skill: https://skilld.dev/gh/dimillian/skills/react-component-performance

This session only. Nothing lands on disk.

referencesexamples.md

≈596 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Examples

Isolate a ticking timer from a long list

Scenario: A message list re-renders every second because a timer (elapsedMs) lives in the parent component. This causes visible jank on large lists.

Goal: Keep UI identical but limit re-renders to the timer area.

Before (problematic pattern):

function Messages({ items, isThinking, processingStartedAt }) {
  const [elapsedMs, setElapsedMs] = useState(0);

  useEffect(() => {
    if (!isThinking || !processingStartedAt) {
      setElapsedMs(0);
      return;
    }
    setElapsedMs(Date.now() - processingStartedAt);
    const interval = window.setInterval(() => {
      setElapsedMs(Date.now() - processingStartedAt);
    }, 1000);
    return () => window.clearInterval(interval);
  }, [isThinking, processingStartedAt]);

  return (
    <div>
      {items.map((item) => (
        <MessageRow key={item.id} item={item} />
      ))}
      <div>{formatDurationMs(elapsedMs)}</div>
    </div>
  );
}

After (isolated ticking state):

type WorkingIndicatorProps = {
  isThinking: boolean;
  processingStartedAt?: number | null;
};

const WorkingIndicator = memo(function WorkingIndicator({
  isThinking,
  processingStartedAt = null,
}: WorkingIndicatorProps) {
  const [elapsedMs, setElapsedMs] = useState(0);

  useEffect(() => {
    if (!isThinking || !processingStartedAt) {
      setElapsedMs(0);
      return;
    }
    setElapsedMs(Date.now() - processingStartedAt);
    const interval = window.setInterval(() => {
      setElapsedMs(Date.now() - processingStartedAt);
    }, 1000);
    return () => window.clearInterval(interval);
  }, [isThinking, processingStartedAt]);

  return <div>{formatDurationMs(elapsedMs)}</div>;
});

function Messages({ items, isThinking, processingStartedAt }) {
  return (
    <div>
      {items.map((item) => (
        <MessageRow key={item.id} item={item} />
      ))}
      <WorkingIndicator
        isThinking={isThinking}
        processingStartedAt={processingStartedAt}
      />
    </div>
  );
}

Why it helps: Only the WorkingIndicator subtree re-renders every second. The list remains stable unless its props change.

Optional follow-ups:

  • Wrap MessageRow in memo if props are stable.
  • Use useCallback for handlers passed to rows to avoid re-render churn.
  • Consider list virtualization if the list is very large.

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill is safe. It provides guidelines and examples for optimizing React component performance. No security issues, malicious patterns, or suspicious external references were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    1/2 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 3db84e6. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 7 months ago

README badge

README badge for dimillian/skills/react-component-performance

Identify render bottlenecks in React components using React DevTools Profiler and apply targeted optimizations like isolating ticking state, stabilizing callbacks with useCallback, and memoizing expensive computations. Use when a React component is slow, re-renders excessively, or has laggy list rendering.

Generated from the current SKILL.md.

Does this skill work with Next.js or other React frameworks?
Yes. The skill targets React component rendering itself, so it applies to any framework built on React, including Next.js, Remix, and Gatsby.
What tools do I need to profile with this skill?
React DevTools Profiler (a browser extension) is the primary tool. The skill uses its Flamegraph and Ranked chart views to identify slow components.
Does this cover server components or only client-side rendering?
The skill focuses on client-side React component performance. Server component optimization falls outside its scope.
Will this skill help with bundle size or initial page load?
No. The skill targets runtime performance of existing components—slow renders, re-render churn, and laggy interactions. For bundle size, see code-splitting or tree-shaking tools.
Can I apply these optimizations to class components?
The examples use hooks (useState, useCallback, useMemo), which are for functional components. Class components use shouldComponentUpdate and PureComponent instead, though the underlying principles are the same.

Generated from the current SKILL.md. These answers refresh after source changes.