~/swaraj.dev
Back to all posts
April 7, 20261 min read

Stop Recreating Style Objects on Every Render

Learn why creating new style objects inside a component causes needless re‑renders and how useMemo can keep UI snappy.

react nativeperformancereact

Insight

In React Native, any inline object—especially style objects—gets a new reference on each render. Since StyleSheet.create returns a static reference, developers often forget that { backgroundColor: theme } inside JSX forces child components to think their props changed, triggering extra layout passes. This hidden cost shows up as jank on low‑end devices.

Example

import { useMemo } from 'react';
import { View, Text, StyleSheet } from 'react-native';

export default function Card({ theme }: { theme: string }) {
  const containerStyle = useMemo(
    () => ({ backgroundColor: theme, padding: 12 }),
    [theme]
  );

  return (
    <View style={[styles.base, containerStyle]}>
      <Text>Styled Card</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  base: { borderRadius: 8, margin: 8 },
});

Takeaway

Memoize dynamic style objects (or move them to StyleSheet.create) so their reference stays stable. This simple change can cut unnecessary renders and keep your UI buttery smooth, especially on Android devices with limited GPU bandwidth.