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