Skip to content

Instantly share code, notes, and snippets.

@paul-vd
Last active May 27, 2020 22:15
Show Gist options
  • Save paul-vd/0f2b5befbd134ee4be3462b2c208aa08 to your computer and use it in GitHub Desktop.
Save paul-vd/0f2b5befbd134ee4be3462b2c208aa08 to your computer and use it in GitHub Desktop.
Default Props Function Component
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