Skip to content

Instantly share code, notes, and snippets.

@createdbymahmood
Last active December 16, 2020 14:12
Show Gist options
  • Save createdbymahmood/dc591fc0ad6fd2734183825eafaab19f to your computer and use it in GitHub Desktop.
Save createdbymahmood/dc591fc0ad6fd2734183825eafaab19f to your computer and use it in GitHub Desktop.
composable hoc
export const composableHoc = (prop: string) => {
return function <T>(Component: ComponentType<T>) {
return function (props: T): JSX.Element {
return <Component {...props} />;
};
};
};
export const compose = (...fns: any[]) =>
fns.reduceRight(
(prevFn, nextFn) => (...args) => nextFn(prevFn(...args)),
value => value
);
export default compose(
composableHoc('withSomeProp'),
)(Component);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment