Skip to content

fix(react-best-practices): correct rule 5.4 - memo checks props not default parameter values - #141

Open
jaryalarshita wants to merge 4 commits into
vercel-labs:mainfrom
jaryalarshita:fix/rule-5-4-memo-default-props
Open

fix(react-best-practices): correct rule 5.4 - memo checks props not default parameter values#141
jaryalarshita wants to merge 4 commits into
vercel-labs:mainfrom
jaryalarshita:fix/rule-5-4-memo-default-props

Conversation

@jaryalarshita

Copy link
Copy Markdown
Contributor

Closes #140

The original rule 5.4 incorrectly claimed that using a default non-primitive parameter (like onClick = () => {}) in a memo component breaks memoization when called without that prop.

This is inaccurate. memo() compares incoming props, not internal default values. When <UserAvatar /> is called without onClick, memo sees undefined === undefined and correctly skips the re-render.

The real issue occurs when the default value is used as a dependency in useEffect, useCallback, or useMemo — a new function instance is created on every render, causing those hooks to re-run unnecessarily.

Changes

  • Corrected the description in rerender-memo-with-default-value.md and AGENTS.md
  • Updated the bad/good examples to show the actual problematic scenario (hook dependency arrays, not memo prop comparison)

@vercel

vercel Bot commented Feb 17, 2026

Copy link
Copy Markdown

@jaryalarshita is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread skills/react-best-practices/rules/rerender-memo-with-default-value.md Outdated
@jaryalarshita
jaryalarshita force-pushed the fix/rule-5-4-memo-default-props branch from c703e45 to 30b1a44 Compare July 16, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong optimization suggestion for react-best-practices #5.4

1 participant