Last active
May 27, 2020 22:15
-
-
Save paul-vd/0f2b5befbd134ee4be3462b2c208aa08 to your computer and use it in GitHub Desktop.
Default Props Function Component
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 from 'react' | |
const withDefaults = <P, DP>(component: React.ComponentType<P>, defaultProps: DP) => { | |
type Props = Partial<DP> & Omit<P, keyof DP> | |
component.defaultProps = defaultProps | |
// @ts-ignore | |
return component as React.ComponentType<Props> | |
} | |
export default withDefaults |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment