Skip to content

Instantly share code, notes, and snippets.

@borispoehland
Last active February 18, 2021 14:15
Show Gist options
  • Save borispoehland/fbd6d0f4901be341218bf16a908bea57 to your computer and use it in GitHub Desktop.
Save borispoehland/fbd6d0f4901be341218bf16a908bea57 to your computer and use it in GitHub Desktop.
Sample HOC for React Typescript
import React, { FC, FunctionComponent } from 'react';
import { LoadingSpinner } from '@components/LoadingSpinner';
interface IProps {
isLoading: boolean;
}
// eslint-disable-next-line @typescript-eslint/ban-types, react/display-name
const WithLoadingSpinner = <P extends object>(Component: FunctionComponent<P>): FC<P & IProps> => ({
isLoading,
...props
}: IProps): JSX.Element => {
if (isLoading) return <LoadingSpinner />;
return <Component {...(props as P)} />;
};
export default WithLoadingSpinner;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment