primefaces / primefaces/primereact

Enchancement: Memoize UI builders in Button

Open
#8,526 1 comment 0 reactions 1 assignee View on GitHub

@sudheerchauhan452-lab is already working on this.

Since Apr 15, 2026.

Type: Performance
Dominant language
CSS
Stars
8.3k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.