with-props-hoc
v1.0.1
Published
Simple Higher Order Component to inject an initialised subset of props in a component
Downloads
2
Maintainers
Readme
withProps
Higher order component to inject a subset of props for code reuse with TypeScript type declaration.
About
import React from 'react'
const withProps = (Composed, props) => own => <Composed {...{ ...props,...own }}>{own.children}</Composed>
Improvements over this one-liner are :
Non-react statics methods are copied over using hoist-non-react-statics.
ref is forwarded to the component being wrapped
displayName will appear as
`withProps${Component.displayName}`
- TypeScript type declaration
⚠ Be aware of other HOC caveats when using this. ⚠
Usage
import withProps from 'with-props-hoc'
const NewComponent = withProps(SourceComponent, props)