Last active
June 3, 2020 16:51
-
-
Save jrwebdev/683e8c3ac46209a39e06296b4b7f1842 to your computer and use it in GitHub Desktop.
Loading 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
interface WithLoadingProps { | |
loading: boolean; | |
} | |
const withLoading = <P extends object>(Component: React.ComponentType<P>) => | |
class WithLoading extends React.Component<P & WithLoadingProps> { | |
render() { | |
const { loading, ...props } = this.props; | |
return loading ? <LoadingSpinner /> : <Component {...props as P} />; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This appears to be due to a bug with TypeScript:
microsoft/TypeScript#28938 (comment)
To fix it for now you'll need to use a cast: