Skip to content

Instantly share code, notes, and snippets.

@hardyscc
Created October 3, 2018 06:33
Show Gist options
  • Save hardyscc/6b1dfb42ecb8ec51426356703560e9bb to your computer and use it in GitHub Desktop.
Save hardyscc/6b1dfb42ecb8ec51426356703560e9bb to your computer and use it in GitHub Desktop.
type StyleRulesCallback<ClassKey extends string = string> = (
props: any,
theme: Theme
) => StyleRules<ClassKey>;
const withPropsStyles = (style: StyleRulesCallback) => (
component: React.ComponentType<any>
) => {
return forwardRef((props, ref) => {
const proxy = (theme: Theme) => style(props, theme);
const hoc = withStyles(proxy)(component);
return props.children
? createElement(hoc, { ...props, ref }, props.children)
: createElement(hoc, { ...props, ref });
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment