Skip to content

Commit

Permalink
Set display name on HOC
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgraham committed Jan 8, 2021
1 parent 9b9fbc9 commit 832cee4
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/utils/hoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@ import { useDispatch } from 'react-redux';
import { useBaseColor, useSecondaryBaseColor } from './hooks';
import { setBaseColor, setSecondaryBaseColor } from '../actions';

export const withBaseColor = (Component) => (props) => {
const dispatch = useDispatch();
const baseColor = useBaseColor();
const secondaryBaseColor = useSecondaryBaseColor();
return (
<Component
{...props}
baseColor={baseColor}
secondaryBaseColor={secondaryBaseColor}
setBaseColor={(color) => {
dispatch(setBaseColor(color));
}}
setSecondaryBaseColor={(color) => {
dispatch(setSecondaryBaseColor(color));
}}
/>
);
};
export function withBaseColor(WrappedComponent) {
const WithBaseColor = (props) => {
const dispatch = useDispatch();
const baseColor = useBaseColor();
const secondaryBaseColor = useSecondaryBaseColor();
return (
<WrappedComponent
{...props}
baseColor={baseColor}
secondaryBaseColor={secondaryBaseColor}
setBaseColor={(color) => {
dispatch(setBaseColor(color));
}}
setSecondaryBaseColor={(color) => {
dispatch(setSecondaryBaseColor(color));
}}
/>
);
};
WithBaseColor.displayName = `WithBaseColor(${
WrappedComponent.displayName || WrappedComponent.name || 'Component'
})`;
return WithBaseColor;
}

0 comments on commit 832cee4

Please sign in to comment.