Skip to content

Instantly share code, notes, and snippets.

@pocojang
Created December 20, 2019 09:31
Show Gist options
  • Save pocojang/9787882d34419b837844210bee70923a to your computer and use it in GitHub Desktop.
Save pocojang/9787882d34419b837844210bee70923a to your computer and use it in GitHub Desktop.
React HOC 컴포넌트
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