File tree Expand file tree Collapse file tree 1 file changed +8
-17
lines changed Expand file tree Collapse file tree 1 file changed +8
-17
lines changed Original file line number Diff line number Diff line change 1
- import { useMemo } from 'react' ;
2
-
3
1
const PROP_WHITELIST = / ^ ( a r i a - | d a t a - | i d $ | o n [ A - Z ] ) / ;
4
2
5
3
export const usePassThroughHtmlProps = ( props , propBlackList : string [ ] = [ ] ) => {
6
4
const componentPropBlacklist = new Set ( propBlackList ) ;
7
- const passThroughPropNames = Object . keys ( props ) . filter (
8
- ( name ) => PROP_WHITELIST . test ( name ) && ! componentPropBlacklist . has ( name )
9
- ) ;
10
5
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 ;
23
14
} ;
You can’t perform that action at this time.
0 commit comments