Skip to content

Commit

Permalink
Improve performance of mergeReactProps (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcpachecog authored Jun 14, 2024
1 parent 14e72c4 commit fe2c0ba
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/mui-base/src/utils/mergeReactProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ export function mergeReactProps<T extends React.ElementType>(
): WithBaseUIEvent<React.ComponentPropsWithRef<T>> {
return Object.entries(externalProps).reduce(
(acc, [key, value]) => {
if (/^on[A-Z]/.test(key) && typeof value === 'function') {
if (
// This approach is more efficient than using a regex.
key[0] === 'o' &&
key[1] === 'n' &&
key.charCodeAt(2) >= 65 /* A */ &&
key.charCodeAt(2) <= 90 /* Z */ &&
typeof value === 'function'
) {
acc[key] = (event: React.SyntheticEvent) => {
let isPrevented = false;

Expand Down

0 comments on commit fe2c0ba

Please sign in to comment.