Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@react-aria/progress/src/useProgressBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export function useProgressBar(props: AriaProgressBarProps): ProgressBarAria {

value = clamp(value, minValue, maxValue);
let percentage = (value - minValue) / (maxValue - minValue);
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

let valueToFormat = formatOptions.style === 'percent' ? percentage : value;
valueLabel = formatter.format(valueToFormat);
}
Expand Down