Skip to content

Commit 832cee4

Browse files
committed
Set display name on HOC
1 parent 9b9fbc9 commit 832cee4

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/utils/hoc.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@ import { useDispatch } from 'react-redux';
33
import { useBaseColor, useSecondaryBaseColor } from './hooks';
44
import { setBaseColor, setSecondaryBaseColor } from '../actions';
55

6-
export const withBaseColor = (Component) => (props) => {
7-
const dispatch = useDispatch();
8-
const baseColor = useBaseColor();
9-
const secondaryBaseColor = useSecondaryBaseColor();
10-
return (
11-
<Component
12-
{...props}
13-
baseColor={baseColor}
14-
secondaryBaseColor={secondaryBaseColor}
15-
setBaseColor={(color) => {
16-
dispatch(setBaseColor(color));
17-
}}
18-
setSecondaryBaseColor={(color) => {
19-
dispatch(setSecondaryBaseColor(color));
20-
}}
21-
/>
22-
);
23-
};
6+
export function withBaseColor(WrappedComponent) {
7+
const WithBaseColor = (props) => {
8+
const dispatch = useDispatch();
9+
const baseColor = useBaseColor();
10+
const secondaryBaseColor = useSecondaryBaseColor();
11+
return (
12+
<WrappedComponent
13+
{...props}
14+
baseColor={baseColor}
15+
secondaryBaseColor={secondaryBaseColor}
16+
setBaseColor={(color) => {
17+
dispatch(setBaseColor(color));
18+
}}
19+
setSecondaryBaseColor={(color) => {
20+
dispatch(setSecondaryBaseColor(color));
21+
}}
22+
/>
23+
);
24+
};
25+
WithBaseColor.displayName = `WithBaseColor(${
26+
WrappedComponent.displayName || WrappedComponent.name || 'Component'
27+
})`;
28+
return WithBaseColor;
29+
}

0 commit comments

Comments
 (0)