Skip to content

Conversation

@plesiecki
Copy link

@plesiecki plesiecki commented Nov 1, 2025

Closes #9127

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@plesiecki plesiecki changed the title do not waste a number formatter Don't waste a number formatter Nov 1, 2025
let formatter = useNumberFormatter(formatOptions);

if (!isIndeterminate && !valueLabel) {
let formatter = useNumberFormatter(formatOptions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unfortunately breaks the rules of hooks. However, within useNumberFormatter we do cache them, so over the lifetime of an app, the expense should become less.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about the rules of hooks. Whether cached or not, it's still suboptimal and can block the main thread unnecessarily.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you running into an issue with it in your application? or is this hypothetical?
there are ways to write this so that the rules of hooks aren't broken, but I'd like to know more information

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.

Create NumberFormatter only if necessary

2 participants