Created
November 30, 2019 16:12
-
-
Save karolisgrinkevicius-home24/75e1e6ebaee6824f028b47c23d9dfcee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { map, groupBy } from 'lodash'; | |
interface SelectableOption { | |
key: string; | |
items: unknown[]; | |
} | |
interface WithGroupedAttributes { | |
selectableOptions: SelectableOption[]; | |
} | |
const withGroupedAttributes = <P extends object>( | |
Component: React.ComponentType<P> | |
): React.FC<P> => ({ | |
selectableOptions, | |
...restProps | |
}: P & WithGroupedAttributes) => ( | |
<Component | |
{...({ | |
...restProps, | |
selectableOptions: map(groupBy(selectableOptions, 'key'), (obj, key) => ({ | |
key, | |
items: obj, | |
})), | |
} as P)} | |
/> | |
); | |
export default withGroupedAttributes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment