Skip to content

Enchancement: Memoize UI builders in Button #8526

Open

Description

@mustafajw07

Problem

In the Button component, the helper functions createIcon, createLabel, and createBadge are executed on every render, regardless of whether their dependent props have changed.

While each computation is relatively small, this can lead to unnecessary recalculations in scenarios where the Button component re-renders frequently (e.g., in lists, forms, or state updates).

Suggested Improvement

Memoize the results of these helper functions using React.useMemo, based on their relevant dependencies.

Example:

const icon = React.useMemo(() => createIcon(), [props.icon, props.loading, props.iconPos]);
const label = React.useMemo(() => createLabel(), [props.label, props.children]);
const badge = React.useMemo(() => createBadge(), [props.badge]);

Benefits

  • Reduces redundant computations on re-render
  • Aligns with React performance best practices
  • Improves efficiency in high-frequency render scenarios
  • Maintains full backward compatibility

Activity

  1. sudheerchauhan452-lab commented on Apr 14, 2026

    @sudheerchauhan452-lab

    Hi, I’d like to work on this issue. Assign it to me please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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