skills/cjharmath/rn-performance/SKILL.md
Performance optimization for React Native. Use when optimizing lists, preventing re-renders, memoizing components, or debugging performance issues in Expo/React Native apps.
npx skillsauth add aiskillstore/marketplace rn-performanceInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
React Native performance issues often stem from unnecessary re-renders, unoptimized lists, and expensive computations on the JS thread. This codebase has performance-critical areas (shot mastery, player lists) with established optimization patterns.
// ✅ CORRECT: Stable function reference
const keyExtractor = useCallback((item: Session) => item.id, []);
<FlatList
data={sessions}
keyExtractor={keyExtractor}
renderItem={renderItem}
/>
// ❌ WRONG: Creates new function every render
<FlatList
data={sessions}
keyExtractor={(item) => item.id}
renderItem={renderItem}
/>
// ❌ WRONG: Using index (causes issues with reordering/deletion)
keyExtractor={(item, index) => `${index}`}
const ITEM_HEIGHT = 80;
const SEPARATOR_HEIGHT = 1;
const getItemLayout = useCallback(
(data: Session[] | null | undefined, index: number) => ({
length: ITEM_HEIGHT,
offset: (ITEM_HEIGHT + SEPARATOR_HEIGHT) * index,
index,
}),
[]
);
<FlatList
data={sessions}
getItemLayout={getItemLayout}
// ... other props
/>
Why it matters: Without getItemLayout, FlatList must measure each item, causing scroll jank.
// Extract to named component
const SessionItem = memo(function SessionItem({
session,
onPress
}: {
session: Session;
onPress: (id: string) => void;
}) {
return (
<Pressable onPress={() => onPress(session.id)}>
<Text>{session.title}</Text>
</Pressable>
);
});
// Stable callback
const handlePress = useCallback((id: string) => {
navigation.push(`/session/${id}`);
}, [navigation]);
// Stable renderItem
const renderItem = useCallback(
({ item }: { item: Session }) => (
<SessionItem session={item} onPress={handlePress} />
),
[handlePress]
);
<FlatList
data={sessions}
renderItem={renderItem}
// ...
/>
<FlatList
data={sessions}
renderItem={renderItem}
keyExtractor={keyExtractor}
getItemLayout={getItemLayout}
// Performance props
removeClippedSubviews={true} // Unmount off-screen items
maxToRenderPerBatch={10} // Items per render batch
windowSize={5} // Render window (screens)
initialNumToRender={10} // Initial render count
updateCellsBatchingPeriod={50} // Batch update delay (ms)
// Prevent extra renders
extraData={selectedId} // Only re-render when this changes
/>
When to use: 1000+ items, complex item components, or FlatList still janky.
import { FlashList } from '@shopify/flash-list';
<FlashList
data={players}
renderItem={renderItem}
estimatedItemSize={80} // Required - estimate item height
keyExtractor={keyExtractor}
/>
Note: This codebase doesn't currently use FlashList. Consider for coach player lists.
// ✅ CORRECT: Memoize expensive calculation
const sortedAndFilteredItems = useMemo(() => {
return items
.filter(item => item.active)
.sort((a, b) => b.score - a.score)
.slice(0, 100);
}, [items]);
// ❌ WRONG: Recalculates every render
const sortedAndFilteredItems = items
.filter(item => item.active)
.sort((a, b) => b.score - a.score);
// ❌ WRONG: Memoizing simple access (overhead > benefit)
const userName = useMemo(() => user.name, [user.name]);
When to use useMemo:
// ✅ CORRECT: Stable callback for child props
const handlePress = useCallback((id: string) => {
setSelectedId(id);
}, []);
// Pass to memoized child
<MemoizedItem onPress={handlePress} />
// ❌ WRONG: useCallback with unstable deps
const handlePress = useCallback((id: string) => {
doSomething(unstableObject); // unstableObject changes every render
}, [unstableObject]); // Defeats the purpose
When to use useCallback:
// Wrap components that receive stable props
const PlayerCard = memo(function PlayerCard({
player,
onSelect
}: Props) {
return (
<Pressable onPress={() => onSelect(player.id)}>
<Text>{player.name}</Text>
<Text>{player.rating}</Text>
</Pressable>
);
});
// Custom comparison for complex props
const PlayerCard = memo(
function PlayerCard({ player, onSelect }: Props) {
// ...
},
(prevProps, nextProps) => {
// Return true if props are equal (skip re-render)
return (
prevProps.player.id === nextProps.player.id &&
prevProps.player.rating === nextProps.player.rating
);
}
);
When to use React.memo:
When NOT to use:
Problem: Selecting entire store causes re-render on any state change.
// ❌ WRONG: Re-renders on ANY store change
const store = useAssessmentStore();
// or
const { userAnswers, isLoading, retakeAreas, ... } = useAssessmentStore();
// ✅ CORRECT: Only re-renders when selected values change
const userAnswers = useAssessmentStore((s) => s.userAnswers);
const isLoading = useAssessmentStore((s) => s.isLoading);
// ✅ CORRECT: Multiple values with shallow comparison
import { useShallow } from 'zustand/react/shallow';
const { userAnswers, isLoading } = useAssessmentStore(
useShallow((s) => ({
userAnswers: s.userAnswers,
isLoading: s.isLoading
}))
);
See also: rn-zustand-patterns/SKILL.md for more Zustand patterns.
import { Image } from 'expo-image';
// expo-image provides caching and performance optimizations
<Image
source={{ uri: player.avatarUrl }}
style={{ width: 50, height: 50 }}
contentFit="cover"
placeholder={blurhash} // Show while loading
transition={200} // Fade in duration
cachePolicy="memory-disk" // Cache strategy
/>
// For lists, add priority
<Image
source={{ uri: player.avatarUrl }}
priority={isVisible ? 'high' : 'low'}
/>
// ❌ WRONG: New object every render
<ChildComponent style={{ padding: 10 }} />
<ChildComponent config={{ enabled: true }} />
// ✅ CORRECT: Stable reference
const style = useMemo(() => ({ padding: 10 }), []);
const config = useMemo(() => ({ enabled: true }), []);
<ChildComponent style={style} />
<ChildComponent config={config} />
// ✅ CORRECT: Or use StyleSheet
const styles = StyleSheet.create({
container: { padding: 10 },
});
<ChildComponent style={styles.container} />
// ❌ WRONG: Inline function creates new element each render
<Parent>
{() => <Child />}
</Parent>
// ✅ CORRECT: Stable element
const child = useMemo(() => <Child />, [deps]);
<Parent>{child}</Parent>
// Setup in development
import React from 'react';
if (__DEV__) {
const whyDidYouRender = require('@welldone-software/why-did-you-render');
whyDidYouRender(React, {
trackAllPureComponents: true,
});
}
// Mark specific component for tracking
PlayerCard.whyDidYouRender = true;
// Quick check for re-renders
function PlayerCard({ player }: Props) {
console.log('PlayerCard render:', player.id);
// ...
}
Problem: JS thread blocked causes UI jank.
// ❌ WRONG: Blocks JS thread
const result = heavyComputation(data); // Takes 500ms
// ✅ CORRECT: Use InteractionManager
import { InteractionManager } from 'react-native';
InteractionManager.runAfterInteractions(() => {
const result = heavyComputation(data);
setResult(result);
});
// ✅ CORRECT: requestAnimationFrame for visual updates
requestAnimationFrame(() => {
// Update after current frame
});
Before shipping list-heavy screens:
keyExtractor (stable callback)getItemLayout (if fixed height)React.memouseCallbackexpo-image with caching| Issue | Solution |
|-------|----------|
| List scroll jank | Add getItemLayout, memoize items |
| Component re-renders too often | Check selector specificity, memoize props |
| Slow initial render | Reduce initialNumToRender, defer computation |
| Memory growing | Check for state accumulation, image cache |
| UI freezes on interaction | Move computation off main thread |
development
Apple Human Interface Guidelines for content display components. Use this skill when the user asks about charts component, collection view, image view, web view, color well, image well, activity view, lockup, data visualization, content display, displaying images, rendering web content, color pickers, or presenting collections of items in Apple apps. Also use when the user says how should I display charts, what's the best way to show images, should I use a web view, how do I build a grid of items, what component shows media, or how do I present a share sheet. Cross-references: hig-foundations for color/typography/accessibility, hig-patterns for data visualization patterns, hig-components-layout for structural containers, hig-platforms for platform-specific component behavior.
tools
Automate HelpDesk tasks via Rube MCP (Composio): list tickets, manage views, use canned responses, and configure custom fields. Always search tools first for current schemas.
testing
Expert Haskell engineer specializing in advanced type systems, pure functional design, and high-reliability software. Use PROACTIVELY for type-level programming, concurrency, and architecture guidance.
tools
GraphQL gives clients exactly the data they need - no more, no less. One endpoint, typed schema, introspection. But the flexibility that makes it powerful also makes it dangerous. Without proper controls, clients can craft queries that bring down your server. This skill covers schema design, resolvers, DataLoader for N+1 prevention, federation for microservices, and client integration with Apollo/urql. Key insight: GraphQL is a contract. The schema is the API documentation. Design it carefully.