Skip to content

Instantly share code, notes, and snippets.

@dwdt
dwdt / withDefaultProps.js
Created January 8, 2021 02:11 — forked from angeloashmore/withDefaultProps.js
React HOC to automatically apply a component's default props before provided props.
import React from 'react'
import hoistNonReactStatics from 'hoist-non-react-statics'
// Returns the components name. If a name cannot be determined, "Component" is
// used.
const getComponentName = Component =>
Component.displayName || Component.name || 'Component'
// Higher order component that automatically applies default props to the
// wrapped component.