extract-default-non-primitive-parameter-to-constant

Extracts non-primitive default React props into constants to preserve referential equality for memoization.

Updated Feb 10, 2026
One-click install
npx skills add https://github.com/ihj04982/my-cursor-settings --skill extract-default-non-primitive-parameter-to-constant
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: extract-default-non-primitive-parameter-to-constant
Source: https://github.com/ihj04982/my-cursor-settings/tree/main/skills/extract-default-non-primitive-parameter-to-constant
Command: npx skills add https://github.com/ihj04982/my-cursor-settings --skill extract-default-non-primitive-parameter-to-constant

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses a common issue in React memoization where non-primitive default parameters (like objects or functions) cause memoization to fail because new instances are created on each render.

Core Features & Use Cases

  • Fixes Memoization: Ensures stable default values for optional parameters in memoized components.
  • Improves Performance: Prevents unnecessary re-renders by maintaining referential equality for default props.
  • Use Case: When using a memoized React component with an optional onClick handler, defining the default as a constant NOOP function prevents the component from re-rendering unnecessarily when the prop is not provided.

Quick Start

Extract the default value for the 'onClick' prop in a memoized component to a constant.

Frequently Asked Questions about extract-default-non-primitive-parameter-to-constant

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does React memoization fail for optional object or array props?

Memoization fails because non-primitive default parameters create new object instances on each render, breaking referential equality checks in React.memo. Extracting these defaults into external constants stabilizes references and prevents unnecessary re-renders.

How do I fix memoization breaking when an optional onClick handler is not provided?

To fix memoization breaking, extract the default onClick handler into a constant outside the component. This ensures the default prop maintains referential equality across renders when the handler is not explicitly provided.

What is the best way to stabilize default props in memoized React components?

The best way to stabilize default props is to extract non-primitive default values into module-level constants. This prevents redefining instances on every render and ensures consistent referential equality for React.memo checks.

Does defining a default object parameter inside a React component cause re-renders?

Yes, defining a default object parameter inside a React component causes re-renders because it generates a new memory reference on each render. Moving the default value to a constant outside the component resolves this performance issue.

When do I need to extract default parameters to constants for JavaScript performance optimization?

You need to extract default parameters to constants when using memoized React components with optional non-primitive props. This optimization is required when default objects, arrays, or functions are redefined per render, failing React.memo referential equality checks.