Skip to content

Commit 16dafbb

Browse files
committed
refactor: use map in favor of reduce
1 parent 77ea07c commit 16dafbb

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

src/PropValidations.tsx

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,33 @@ export const PropValidations: React.FunctionComponent<{ prop: IProp | IResolvedP
1111

1212
return (
1313
<>
14-
{Object.entries(validations).reduce(
15-
(elems, [k, v]) => {
16-
let type = typeof v;
17-
18-
if (k === 'default' && ['object', 'boolean'].includes(type)) {
19-
v = safeStringify(v);
20-
21-
type = typeof v;
22-
}
23-
24-
if (type === 'boolean') {
25-
elems.push(
26-
<div key={k}>
27-
<b>{k}:</b> {v.toString()}
28-
</div>
29-
);
30-
} else if (type !== 'object') {
31-
elems.push(
32-
<div key={k}>
33-
<b>{k}:</b> {v}
34-
</div>
35-
);
36-
}
37-
38-
return elems;
39-
},
40-
[] as Array<React.ReactElement<any>>
41-
)}
14+
{Object.entries(validations).map(([k, v]) => {
15+
let type = typeof v;
16+
17+
if (k === 'default' && ['object', 'boolean'].includes(type)) {
18+
v = safeStringify(v);
19+
20+
type = typeof v;
21+
}
22+
23+
if (type === 'boolean') {
24+
return (
25+
<div key={k}>
26+
<b>{k}:</b> {v.toString()}
27+
</div>
28+
);
29+
}
30+
31+
if (type !== 'object') {
32+
return (
33+
<div key={k}>
34+
<b>{k}:</b> {v}
35+
</div>
36+
);
37+
}
38+
39+
return null;
40+
})}
4241
</>
4342
);
4443
}

0 commit comments

Comments
 (0)