Last active
February 18, 2021 14:15
-
-
Save borispoehland/fbd6d0f4901be341218bf16a908bea57 to your computer and use it in GitHub Desktop.
Sample HOC for React Typescript
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
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