Created
December 20, 2019 09:31
-
-
Save pocojang/9787882d34419b837844210bee70923a to your computer and use it in GitHub Desktop.
React HOC 컴포넌트
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
const Foo = ({ result }) => <ResultComponent result={result} />; | |
const withRequest = BaseComponent => ({ bar, ...props }) => { | |
const { result, loading, error } = useRequest(bar); | |
return ( | |
<BaseComponent {...props} result={result} loading={loading} error={error} /> | |
); | |
}; | |
const withError = branch(({ error }) => error, ErrorComponent); | |
const withLoading = branch(({ loading }) => loading, LoadingComponent); | |
export default compose( | |
withRequest, | |
withLoading, | |
withError | |
)(Foo); | |
// https://medium.com/@albertchu539/higher-order-components-in-a-react-hooks-world-69fe1f0b0791 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment