Skip to content

Wrong optimization suggestion for react-best-practices #5.4 #140

@grundmanise

Description

@grundmanise

5.4 Extract Default Non-primitive Parameter Value from Memoized Component to Constant

Gives an example where memo should fail. But that's not the case – memo doesn't compare inner component arguments; it compares incoming props. Therefore, the rule and example provided are misleading and don't cause performance issues.

This will memo just fine:

const UserAvatar = memo(function UserAvatar({ onClick = () => {} }: { onClick?: () => void }) {
  // ...
})

// Used without optional onClick
<UserAvatar />

Link: https://github.com/vercel-labs/agent-skills/blob/main/skills/react-best-practices/AGENTS.md#54-extract-default-non-primitive-parameter-value-from-memoized-component-to-constant

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions