Skip to content

Commit 10e0d89

Browse files
fix: remove useMemo from usePassThroughHtmlProps (#601)
Remove `useMemo` here as it had no effect because the returned object is always spreaded.
1 parent ab0760f commit 10e0d89

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed
Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
1-
import { useMemo } from 'react';
2-
31
const PROP_WHITELIST = /^(aria-|data-|id$|on[A-Z])/;
42

53
export const usePassThroughHtmlProps = (props, propBlackList: string[] = []) => {
64
const componentPropBlacklist = new Set(propBlackList);
7-
const passThroughPropNames = Object.keys(props).filter(
8-
(name) => PROP_WHITELIST.test(name) && !componentPropBlacklist.has(name)
9-
);
105

11-
return useMemo(
12-
() => {
13-
return passThroughPropNames.reduce(
14-
(acc, val) => ({
15-
...acc,
16-
[val]: props[val]
17-
}),
18-
{}
19-
);
20-
},
21-
passThroughPropNames.map((name) => props[name])
22-
);
6+
const returnVal = {};
7+
for (const name in props) {
8+
if (PROP_WHITELIST.test(name) && !componentPropBlacklist.has(name)) {
9+
returnVal[name] = props[name];
10+
}
11+
}
12+
13+
return returnVal;
2314
};

0 commit comments

Comments
 (0)